如何将此json代码反序列化为c#对象?

时间:2017-04-25 17:57:18

标签: c# facebook-graph-api json.net json-deserialization

我有一个来自facebook图的json代码

{  
   "data":[  
      {  
         "id":"00000000000",
         "name":"Music1"
      },
      {  
         "id":"00000000001",
         "name":"Music2"
      },
      {  
         "id":"00000000002",
         "name":"Music3"
      }
   ],
   "paging":{  
      "cursors":{  
         "before":"ODYxODU3ODI4NDgZD",
         "after":"MTkwMDA4MDc0MzcyMjM1"
      },
      "next":"https://graph.facebook.com/v2.9/USER_ID/music?access_token=MY_ACCESS_TOKEN&pretty=0&fields=id%2Cname&limit=25&after=MTkwMDA4MDc0MzcyMjM1"
   }
}

我找到了一个在线json2csharp代码生成器并生成它:

public class Datum
{
    public string id { get; set; }
    public string name { get; set; }
}

public class Cursors
{
    public string before { get; set; }
    public string after { get; set; }
}

public class Paging
{
    public Cursors cursors { get; set; }
    public string next { get; set; }
}

public class RootObject
{
    public List<Datum> data { get; set; }
    public Paging paging { get; set; }
}

我尝试以多种方式将其反序列化为此类结构,但我总是遇到困难。我可以反序列化&#34;分页&#34;和&#34;光标&#34;正确的,但我还没有找到反序列化数据的方法:id,name&#34;。你能帮我解决这个问题吗?

0 个答案:

没有答案