【发布时间】:2014-10-31 23:24:43
【问题描述】:
使用 xamarin 跨平台开发,我想从 url 打印一条 json 消息并在 listview 中打印。我编写代码没有错误,但有一些错误。我不会工作。仅对于验证输出,我在输出屏幕中打印按钮。我将显示但未打印列表视图。请更正我的代码。
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; }
【问题讨论】:
-
您确认您的数据被正确填充了吗?
标签: json listview xamarin.ios xamarin cross-platform