删除预先挂起的"数据"来自json字符串

时间:2017-10-02 17:28:49

标签: c# json json.net

我正在调用第三方API,我收到的json字符串如下所示:

{
  "data":[
          {"id":197567,"name":"101","url":"http://www.foobar1.com"},
          {"id":197568,"name":"102","url":"http://www.foobar2.com"},
          .....
          {"id":197569,"name":"120","url":"http://www.foobar20.com"}
        ],
  "offset":0,
  "pageSize":2,
  "count":20
}

然后我有一个班级FoorBarURIs

private class FoorBarURLs
{
    public int id { get; set; }
    public string name { get; set; }
    public string url { get; set; }
}

所以,我并不关心offsetpagesizecount。我只需要data内的数据。

鉴于我开始的只是一个字符串,如何从data中提取该列表,以便我可以这样做:

List<FoorBarURLs> myList = JsonConvert.DeserializeObject<List<FoorBarURLs>>(???)

1 个答案:

答案 0 :(得分:4)

使用临时JObject

var obj = JObject.Parse(json)["data"].ToObject<List<FoorBarURLs>>();