我正在为Windows Phone 8工作..
我需要从url检索Json数据,我需要在数组中显示..
我的网址有这样的jsondata ..
{ id: 9
address: "abc"
city: " chennai"
contact1: ""
contact2: ""
country: " india"
description: ""
}
我想知道如何检索这些数据并将其存储在数组中?
这是我用来检索Json数据的语句。
private string REST_URL = "my url"; //i'm using my url here to extract the json data..
String servicePath = REST_URL + "/data/" + query;
Detail[] detail = JsonConvert.DeserializeObject<Detail[]>(servicePath);
return detail;
我完整的Json数据
[
{
"id": 01,
"address": "12asdf",
"city": " chennai",
"contact1": "",
"contact2": "",
"country": " india",
"description": "",
"name": " david",
"region": "",
"state": " 033",
"website": "",
"image": "",
"PrayerTime": {
"id": 01,
"PrayerTime1": "00:52",
"PrayerTime2": "21:04",
"PrayerTime3": "12:27",
"PrayerTime4": "05:35",
"PrayerTime5": "21:04",
"created_at": null,
"PrayerTime6": "04:01",
"updated_at": null,
"organization_id": 001
}
},.............
}
答案 0 :(得分:1)
首先确保您的模型正确无误。由于@Xyroid声明使用json2csharp.com,它允许您简单地复制和粘贴您的json,它将生成相应的c#代码。
您无法将URL提供给解析器,您首先必须将JSON下载为字符串。要下载字符串,只需使用HttpClient,您甚至可以使用PCL。
var httpClient = new System.Net.Http.HttpClient();
string jsonData = httpClient.GetStringAsync(url);