Json响应几个表(?)

时间:2014-10-23 16:41:33

标签: c# asp.net json

如何以以下形式解析Json响应:

www.extradelar.se/match

如果我理解这个响应是正确的,它是一个由三个响应组成的数组,在这种情况下如何解析它们?如何将其反序列化为我的RootObject?

1 个答案:

答案 0 :(得分:0)

我不确定它是否由于复制粘贴而提供的json无效:

使用http://jsonlint.com/可以验证缩进你的json:

一旦缩进,就会更容易看到。

以上JSON是数组数组,其中每个数组都包含一个对象。

通常的JSON有点奇怪,但也许你有自己的理由。

使用像JSON.net这样的库,您可以轻松地将该数据解析为C#对象。

希望这有帮助


编辑:

POCO课程:

public class RootObject
{
    public string match_id { get; set; }
    public string no_repick { get; set; }
    public string no_agi { get; set; }
    public string drp_itm { get; set; }
    public string no_timer { get; set; }
    public string rev_hs { get; set; }
    public string no_swap { get; set; }
    public string no_int { get; set; }
    public string alt_pick { get; set; }
    public string veto { get; set; }
    public string shuf { get; set; }
    public string no_str { get; set; }
    public string no_pups { get; set; }
    public string dup_h { get; set; }
    public string ap { get; set; }
    public string br { get; set; }
    public string em { get; set; }
    public string cas { get; set; }
    public string rs { get; set; }
    public string nl { get; set; }
    public string officl { get; set; }
    public string no_stats { get; set; }
    public string ab { get; set; }
    public string hardcore { get; set; }
    public string dev_heroes { get; set; }
    public string verified_only { get; set; }
    public string gated { get; set; }
}

<强> JSON.NET

private string getMatchId()
{
    using (var webClient = new System.Net.WebClient())
    {
        const string url = @"http://www.extradelar.se/match"; 
        var json = webClient.DownloadString(url);
        var matchen = JsonConvert.DeserializeObject<List<List<RootObject>>>(json);
        var matchId = matchen[0][0].match_id;

        return matchId;
    }
}