I want to loop an array of JSON objects but it keeps giving me error
[
{
"key" : "501",
"latitude" : 3.0691697,
"longitude" : 333.64444639369011,
"distance" : 5,
},
{
"key" : "502",
"latitude" : 3.073096722364426,
"longitude" :12.4444000,
"distance" : 487,
}
]
The code example
if let value = response.result.value {
let json = JSON(value)
// This is the part Where I got stuck
for item in json {
print (item["latitude"]) // Keep giving me "Latitude is not a subscript of JSON"
}
}
If I print item to see the value, I will get
("0", {
"latitude" : 3.0691697,
"longitude" : 333.64444639369011,
"key" : "501",
"distance" : 5
})
("1", {
"latitude" : 3.073096722364426,
"longitude" : 12.4444000,
"key" : "502",
"distance" : 487
})
What should I do to solve this problem?
let json = JSON(value)tolet json = JSON(value) as! [String:AnyObject]And tryjsonwithSwiftyJson.