我需要反序列化類型Dictionary的JSON字典到列表(List),我正在使用JSON.Net來達到此目的。當然,它是一個了不起的圖書館,它只是我被卡住了!反序列化一個JSON字典<int,CustomType>到列表<CustomType>
我訂閱一些API的響應正如你可以看到下面:
"team_details": {
"0": {
"index": 1,
"team_id": "1..",
"team_name": "Research Team",
"team_url": "...",
"role": "Administrator"
},
"1": {
"index": 2,
"team_id": "2..",
"team_name": "WB Team",
"team_url": "...",
"role": "User"
}
}
我需要用這個將其轉換爲List<Team>
,隊員:
Class Teams{
public int Index{get;set;}
public String TeamName{get;set;}
...
}
首先,你要確保你的[JSON是有效的(http://jsonlint.com/)? – mason
這個JSON是有效的,它只是有點尷尬,列表不是作爲一個數組存儲的,而是作爲鍵值對象,其中鍵是索引。 – Davio
是的,它是有效的,它的內部讓我們說一個JsON字典。 – bhuvin