i am very new to json parsing and tried to parse a json file which has list of cars but when i do parse, it gives out nil
func jsonTwo(){
let url = Bundle.main.url(forResource: "car_list", withExtension: "json")!
let data = try! Data(contentsOf: url)
let JSON = try! JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]
print(".........." , JSON , ".......")
let brand = JSON?["models"] as? [[String : Any]]
print("=======",brand,"=======")
}
and when i made some modifications to this code as below
func jsonTwo(){
let url = Bundle.main.url(forResource: "car_list", withExtension: "json")!
let data = try! Data(contentsOf: url)
let JSON = try! JSONSerialization.jsonObject(with: data, options: [])
print(".........." , JSON , ".......")
let brand = JSON["brand"] as? [[String : Any]]
print("=======",brand,"=======")
}
then i get and error saying "Type 'Any' has no subscript members"
below is a sample of the json file that i am using
[{"brand": "Aston Martin", "models": ["DB11","Rapide","Vanquish","Vantage"]}]