如何在 Windows Phone 中解析 JSON



我想解析此页面

该页面包含如下 json 数据:

{"List":[{"num":"1","name":"hello","ox_score":"30","between_score":"30","order_score":"30","total_score":"90"}]}

我尝试了下面的代码。(我用过JSON.NET)但我对"列表"很感兴趣,我也尝试了 JArray 和......o["列表"]["名称"],但我无法获得正确的结果。下面的代码还返回空消息。请帮帮我。

法典

public void connection()
        {
            string uriString = "http://kah601.cafe24.com/jp_mango_loadboard.php";
            WebClient wc = new WebClient();
            wc.Headers["Accept"] = "application/json";

            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
            wc.DownloadStringAsync(new Uri(uriString));

        }
        void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            JObject o = JObject.Parse(e.Result);

            String name = (string) o["name"];
            String ox_score = (string) o["ox_score"];
            String between_score = (string) o["between_score"];
            String order_score = (string) o["order_score"];
            String total_score = (string) o["total_score"];
            String rank_result = name + ox_score + between_score + order_score + total_score;
            MessageBox.Show(rank_result);
        }

鉴于它是一个列表,您应该索引 JArray 的元素。下面是一个示例代码来帮助您(请注意 [0] =>引用 JArray 的第一个元素):

void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    JObject o = JObject.Parse(e.Result);
    JArray a = (JArray)o["List"];
    Debug.WriteLine("{0}", (String)a[0]["name"]);
}

相关内容

  • 没有找到相关文章

最新更新