SWIFT 2: Loop through JSON array

The variable jsonResult is an array of dictionaries, so you can loop through the array with

for anItem in jsonResult as! [Dictionary<String, AnyObject>] { // or [[String:AnyObject]]
  let personName = anItem["name"] as! String
  let personID = anItem["id"] as! Int
// do something with personName and personID
}

In Swift 3 the unspecified JSON type has been changed to Any

for anItem in jsonResult as! [Dictionary<String, Any>] { ... // or [[String:Any]]

Tags:

Loops

Json

Swift2