如何在字典相同键中附加字典

时间:2019-05-02 02:46:01

标签: json swift dictionary nsdictionary

我想创建字典发送给API服务器,例如:

var member = ["Member":["Name":"John"],["ID":"001"],["Name":"Andy"],["ID","002"]]

如何在Swift for循环中使用?

我使用:

member.updateValue([["Name":"Chris"],["ID","004"]], forKey: "Member")

它打印:

["Member":["Name":"Chris"],["ID","004"]]

1 个答案:

答案 0 :(得分:0)

首先,您更改字典结构 您可以添加新元素

var member = ["Member":[["Name":"John"],["ID":"001"],["Name":"Andy"],["ID","002"]]]
member["Member"]!.insert((["Name":"Chris"],["ID","004"]), at: 0)
print("member = \(member)")