0

我想解析这个页面

该页面具有如下 json 数据:

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

我尝试了下面的代码。(我使用过JSON.NET)但我对“列表”感到担忧,我也尝试了 JArray 和... o["Lists"]["name"] 但我无法得到正确的结果。下面的代码也返回空消息。请帮帮我。

代码

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);

        }
4

1 回答 1

2

鉴于它是一个列表,您应该索引 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"]);
}
于 2012-09-23T10:29:10.840 回答