2

请帮助我,如何在 Windows Phone 7 中使用给定的 URL 进行 json 解析https://data.cityofchicago.org/api/views/xzkq-xp2w/rows.json?search=rahm

4

1 回答 1

0

将 newtonnsoft json 库添加到 Visual Studio 并使用此代码

    WebClient webClient = new WebClient();
    webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(downloadAboutCompleted);
webClient.OpenReadAsync(new Uri("https://data.cityofchicago.org/api/views/xzkq-xp2w/rows.json?search=rahm"), c);

private void downloadAlbumCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error == null && !e.Cancelled)
            {
                 using (StreamReader httpwebStreamReader = new StreamReader(e.Result))
                {
                    var results = httpwebStreamReader.ReadToEnd();
                System.Diagnostics.Debug.WriteLine(results):
                    var json = JObject.Parse(results);
                System.Diagnostics.Debug.WriteLine(json):

                    foreach (JObject array in json["meta"]["view"])
                    {
                        JObject obj = JObject.Parse(array.ToString());
                        string id= (string)obj["id"];
                        string name= (string)obj["name"];

                System.Diagnostics.Debug.WriteLine(id + name):
                    }

                }

            }
        }
于 2013-03-01T15:44:25.053 回答