简体   繁体   English

我怎样才能从URL检索json数据并将其存储在数组中呢?

[英]how can i retrieve the json data from url and store it in an array..?

i'm working for windows phone 8.. 我正在为Windows Phone 8工作。
i need to retrieve the Json data from url and i need to display in an array.. 我需要从URL检索Json数据,并且需要显示在数组中。
my url have this jsondata like this.. 我的网址具有这样的jsondata。

 {       id: 9
            address: "abc"
            city: " chennai"
            contact1: ""
            contact2: ""
            country: " india"
            description: ""
}

i would like to know how to retrieve this data and store it in an array? 我想知道如何检索此数据并将其存储在数组中?

here is the statements i used to retrieve the Json data. 这是我用来检索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;

my complete Json data 我完整的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
    }
  },.............
  }

First ensure that your model is correct. 首先确保您的模型正确。 As @Xyroid stated use json2csharp.com , which allows you to simply copy and paste your json and it will generate the corresponding c# code. 如@Xyroid所述,请使用json2csharp.com ,它使您可以简单地复制并粘贴json并将生成相应的c#代码。

You can't give the URL to your parser, you will first have to download the JSON as string. 您无法将URL提供给解析器,首先必须将JSON作为字符串下载。 To download the string simply use the HttpClient which you can even use in a PCL . 要下载字符串,只需使用HttpClient ,您甚至可以在PCL中使用它。

var httpClient = new System.Net.Http.HttpClient();
string jsonData = httpClient.GetStringAsync(url);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM