我从Box API调用中得到了这个JSON:
{"total_count":4,
"entries":[
{"type":"folder","id":"3102883693","sequence_id":"0","etag":"0","name":"Deployments"},
{"type":"folder","id":"3460455852","sequence_id":"0","etag":"0","name":"MARKETING"},
{"type":"folder","id":"2535410485","sequence_id":"1","etag":"1","name":"Plans"},
{"type":"folder","id":"3132381455","sequence_id":"0","etag":"0","name":"Projects"},
],
"offset":0,
"limit":100,
"order":[
{"by":"type","direction":"ASC"},
{"by":"name","direction":"ASC"}
]
}
我试过这个让它进入课堂但我无法得到我的名单:
var folders = new JavaScriptSerializer().Deserialize<List<FolderItems>>(response.Content);
以下是我的课程:
public class FolderItems
{
public int total_count { get; set; }
public List<Entry> entries { get; set; }
public int offset { get; set; }
public int limit { get; set; }
public List<Order> order { get; set; }
}
public class Entry
{
public string type { get; set; }
public int id { get; set; }
public int sequence_id { get; set; }
public string etag { get; set; }
public string name { get; set; }
}
public class Order
{
public string by { get; set; }
public string direction { get; set; }
}
答案 0 :(得分:2)
根据您的JSON,您有一个外部对象,而不是列表。
var folder = new JavaScriptSerializer().Deserialize<FolderItems>(response.Content);
您应该反序列化为单个FolderItems
对象,并在该对象上包含条目列表。