ios - How do I pluck this specific node out of from this JSON array? -
i have array being returned in xcode
outputs following:
["userdetails": { id = 31; "user_email" = "steve@gmail.com"; "user_name" = "steve downs"; }, "communities": <__nsarrayi 0x600000245f40>( { id = 5; name = south; }, { id = 13; name = hurraharry; }, { id = 15; name = enclliffet; } ) ]
the code below correctly assigns values contained within "communities" respective variables.
let json = try jsonserialization.jsonobject(with: data!, options: .allowfragments) as? [string:anyobject] print (json!) if let arr = json?["communities"] as? [[string:string]] { self.communitiesarray = arr.flatmap { $0["name"]!} self.communityidsarray = arr.flatmap { $0["id"]!} } if let arr = json?["userdetails"] as? [anyobject] { self.playerid = (arr.flatmap { $0["id"]!} (anyobject)) as! [string] print (self.playerid); }
however i'm having trouble assigning id
"userdetails"
. how take id
"userdetails"
, assign self.playerid?
you can try this
if let dict = json?["userdetails"] as? [string:string] { self.playerid = dict["id"] }
Comments
Post a Comment