I am trying to get Attendance Value from this json file "321" , the Date "654" and the value "123" from the "Number" in "@attributes". I have manage to filter through the levels but I was wondering if there is a more efficient way of accessing values in levels greater than three. Or is there a library similar to linq in csharp.
Can I just jump to "GameData" and get all the GameData and store to a list of objects.
or just a chain e.g:
json["level1"].["level2"].["level3"]
Json:
{
"Feed":{
"Doc":{
"Comp": {
},
"GameData": {
"GameInfo": {
"Attendance": 321,
"Date": 654,
"ID": 00
}
},
"GameData": {
"GameInfo": {
"Attendance": 321,
"Date": 654
"ID": 01
}
}
},
"@attributes": {
"Number": 123
}
}
}
Code:
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String: AnyObject]
if let articlesFromJson = json["Feed"] as? [String: AnyObject]{
print("level1")
if let aFromJson = articlesFromJson["Doc"] as? [String: AnyObject]{
print("level2")
if let aFromJson = articlesFromJson["GameData"] as? [String: AnyObject]{
print(aFromJson)
}
}
}