Reputation: 1948
"groups" : {
"232" : {
"name" : "John",
"age" : "22"
}
},
"143" : {
"name" : "Dylan",
"age" : "22"
}
}
How to get "name" using swiftyJSON? I got the id value but ["name"]'s always nil with this code:
for (results,subJson):(String, JSON) in json["groups"] {
let id = results
print(id) //--> 232
let name = subJson["\(id)"]["name"].string
print(name) //--> nil
}
Upvotes: 1
Views: 152
Reputation: 70098
The name
key is inside subJson
, remove the id
subscript:
for (id, subJson):(String, JSON) in json["groups"] {
print(id)
if let name = subJson["name"].string {
print(name)
}
}
Upvotes: 1