2016-07-14 114 views
0

我想在字典改造這個JSON用於補充一個循環轉換JSON來字典C#

看看我的代碼:

string json = @"{""name"":""Joe"",""note"":{""a1"":10,""a2"":9,""a3"":5}}"; 

Dictionary<string, object> dictionaryLevelOne = JsonConvert.DeserializeObject<Dictionary<string, object>>(json); 
Dictionary<string, object> dictionaryLevelTwo = JsonConvert.DeserializeObject<Dictionary<string, object>>(dictionaryLevelOne ["note"]); 

回答

3

您需要通過dictionaryLevelOne["note"]作爲一個字符串。

string json = @"{""name"":""Joe"",""note"":{""a1"":10,""a2"":9,""a3"":5}}"; 

Dictionary<string, object> dictionaryLevelOne = JsonConvert.DeserializeObject<Dictionary<string, object>>(json); 
Dictionary<string, object> dictionaryLevelTwo = JsonConvert.DeserializeObject<Dictionary<string, object>>(dictionaryLevelOne["note"].ToString()); 
+0

它的工作!謝謝 –