0
使用xamarin跨平臺開發我想從url打印json消息並在列表視圖中打印。我寫代碼沒有錯誤,但有一些錯誤。我不會工作。僅用於驗證輸出,僅打印輸出屏幕中的按鈕。我會顯示,但列表視圖不是打印。請記錄我的代碼。使用xamarin跨平臺不能在列表視圖中使用xamarin跨平臺打印json消息
static ListView listview;
static Button button;
public MainPage()
{
listview = new ListView() { RowHeight = 40 };
button = new Button() { Text = "search Again" };
var stack = new StackLayout()
{
VerticalOptions = LayoutOptions.FillAndExpand,
Children = { button, listview },
};
this.Content = stack;
GetData();
}
async static void GetData()
{
WeatherReport res = new WeatherReport();
try
{
string contents;
string Url = String.Format("http://23.253.66.248:8080/icc/api/venue/search/? lat=39.540544&lon=-104.866115&appkey=123Chesse&restName=MyMacChennai&organization=MyMacChennai");
HttpClient hc = new HttpClient();
contents = await hc.GetStringAsync(Url);
res = JsonConvert.DeserializeObject<WeatherReport>(contents);
listview.ItemsSource = res.list;
}
catch (System.Exception sysExc)
{
// Do something to log this error.
throw;
}
}
public class WeatherReport
{
public WeatherReport()
{
list = new List<WeatherReport>();
}
[JsonProperty(PropertyName = "cod")]
public string cod { get; set; }
[JsonProperty(PropertyName = "message")]
public string message { get; set; }
[JsonProperty(PropertyName = "cnt")]
public int cnt { get; set; }
[JsonProperty(PropertyName = "list")]
public List<WeatherReport> list { get; set; }
您是否驗證過您的數據正在填充正確? – Jason 2014-10-31 17:01:14