我已经能够弄清楚如何调用我的Web服务器,加载JSON,循环遍历它并输出值。但是,如何将此数据填充到单元格中。例如,我想输出返回表中的3年。我该怎么做呢?
async Task GetTowInfo()
{
loadingIndicator.StartAnimating ();
HttpClient client = new HttpClient ();
HttpResponseMessage response = await client.GetAsync ("myurl.com");
HttpContent content = response.Content;
var result = await content.ReadAsStringAsync ();
try
{
var parsed = JsonConvert.DeserializeObject<RootObject>(result);
foreach (var year in parsed.DATA.YEARMFG)
{
Console.WriteLine("Year: {0}", year);
}
}
catch (Exception e) {
Console.WriteLine (e);
}
loadingIndicator.StopAnimating ();
}
public class DATA
{
public List<int> YEARMFG { get; set; }
public List<string> MAKE { get; set; }
public List<string> MODEL { get; set; }
public List<string> ENGINE { get; set; }
public List<int> TOWLIMIT { get; set; }
public List<string> NOTE1 { get; set; }
public List<string> NOTE2 { get; set; }
}
public class RootObject
{
public int ROWCOUNT { get; set; }
public List<string> COLUMNS { get; set; }
public DATA DATA { get; set; }
}
<!----JSON------>
{
"ROWCOUNT": 3,
"COLUMNS": [
"YEARMFG",
"MAKE",
"MODEL",
"ENGINE",
"TOWLIMIT",
"NOTE1",
"NOTE2"
],
"DATA": {
"YEARMFG": [
2012,
2012,
2012
],
"MAKE": [
"Chevrolet/GMC",
"Chevrolet/GMC",
"Chevrolet/GMC"
],
"MODEL": [
"Avalanche 1500 4WD",
"Avalanche 1500 4WD",
"Avalanche 1500 4WD"
],
"ENGINE": [
"5.3L V-8",
"5.3L V-8",
"5.3L V-8"
],
"TOWLIMIT": [
5000,
5500,
8000
],
"NOTE1": [
"3.08 axle ratio",
"3.42 axle ratio",
"3.42 axle ratio"
],
"NOTE2": [
"",
"",
"Cooling or other accessory package required "
]
}
}