2015-05-19 14 views
0

我從盒API調用此JSON:爲什麼我的JavaScriptSerializer()。Deserialize()不起作用?

{"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

不工作怎麼樣? – artm

+0

我的文件夾列表爲空 –

回答

2

根據您的JSON,您只有一個外部對象,而不是一個列表。

var folder = new JavaScriptSerializer().Deserialize<FolderItems>(response.Content); 

你應該反序列化到一個單一的FolderItems對象與對象條目列表。

+0

是的,這是我的錯誤。謝謝!! –