"groups" : {
"232" : {
"name" : "John",
"age" : "22"
}
},
"143" : {
"name" : "Dylan",
"age" : "22"
}
}
如何获得" name"使用swiftyJSON?我得到了id值,但["名称"]总是没有这个代码:
for (results,subJson):(String, JSON) in json["groups"] {
let id = results
print(id) //--> 232
let name = subJson["\(id)"]["name"].string
print(name) //--> nil
}
答案 0 :(得分:1)
name
密钥位于subJson
内,删除了id
下标:
for (id, subJson):(String, JSON) in json["groups"] {
print(id)
if let name = subJson["name"].string {
print(name)
}
}