1

我正在为 windows phone 8 工作。
我需要从 url 检索 Json 数据,我需要在数组中显示。
我的 url 有这样的 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
    }
  },.............
  }
4

1 回答 1

1

首先确保您的模型是正确的。正如@Xyroid 所说,使用json2csharp.com,它允许您简单地复制和粘贴您的 json,它将生成相应的 c# 代码。

您不能将 URL 提供给解析器,您首先必须将 JSON 作为字符串下载。要下载字符串,只需使用您甚至可以在PCL中使用的HttpClient

var httpClient = new System.Net.Http.HttpClient();
string jsonData = httpClient.GetStringAsync(url);
于 2013-11-07T15:04:56.823 回答