Playground:
import UIKit
let people = [ [
"name" : "Bob",
"Age" : 35,
"cars" : [
["type" : "Mercedes GL",
"occupancy" : 7,
"mpg" : 21],
["type" : "Mazda",
"occupancy" : 2,
"mpg" : 24] ]
],[
"name" : "Billy",
"Age" : 26,
"cars" : [
["type" : "VW Golf",
"occupancy" : 5,
"mpg" : 30] ]
]
]
print(people[0]["name"]!)
print(people[0]["cars"]![0]["occupancy"])
The was print function gives me Bob's name. However I am struggling to get the occupancy of his Mercedes car. The second print command gives me "Type 'Any' has no subscript members" as an error. How can I extract the data from the above structure?
Many thanks