2017-06-05 114 views
-2

我想將字典中的數據保存爲以下格式,然後必須將其轉換爲json。iOS中的嵌套字典Swift

[{"id":"1", 
"name":[{"id":"2","name":"k"},{"id":"6","name":"kk"}]", 
"pass":"123"}, 
{"id":"2", 
"name":[{"id":"2","name":"k"},{"id":"6","name":"kk"}]", 
"pass":"234"} 
] 

它在詞典中得到了字典和單個字符串。這是我正在嘗試,但無法獲得理想的結果。

var myDictionary = Dictionary<String, AnyObject>() 
+1

它不是'Dictionary'它是'數組''dictioaries –

+0

@NiravD yup。所以我怎麼能做到這一點? –

+0

我是新來的swift。 –

回答

3
let arrOfData = [["id":"1","pass":"123","name":[["id":"2","name":"k"],["id":"6","name":"kk"]]], 
       ["id":"2","pass":"234","name":[["id":"2","name":"k"],["id":"6","name":"kk"]]]] 

這裏u能看到,如果你想在你可以使用它像let dict2 = ["data":arrOfData]一個字典存儲現在,這將轉換成一個單一的詞典像Array<Dictionary,AnyObject>的陣列。