Update : JSON Array Parsing in Swift Language – Swift 3 – iOS 10 – Xcode 8

Swift JSON
Swift JSON

So, how to parse following type of JSON?

Create JSON Array Object :

Parse JSON Array Object :

Complete code snippet with UITableView:

Posted a gist on github.

Helping, Learning, Coding 🙂

  • Marcello

    Hello, unfortunately the code does not work .. can you help me?

  • Robert

    Hello. Thanks for this post. But I got this message ‘Ambiguous use of subscript’ at the line ‘let aObject = arrJSON[index] as! [String : AnyObject]’. Any help is greatly appreciated.

    • Ashish Kakkad

      Error is at my github code? Which version of Xcode/Swift you are using?

      • ali ghanavati

        in xcode 8
        in simulator is ok but when select the phone got this message ‘Ambiguous use of subscript’ at the line ‘let aObject = arrJSON[index] as! [String : AnyObject]’

    • cat vinchy

      Use NSArray instead of AnyObject in this line :

      let allContacts = try JSONSerialization.jsonObject(with: allContactsData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : AnyObject]

      use this line :
      let allContacts = try JSONSerialization.jsonObject(with: allContactsData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : NSArray]

  • mj

    i have the same problem. Xcode 8

  • Mido Cool

    Hey bro, thanks for this awesome lesson. It worked for me perfect i’m new to swift i have no prior experience in coding. can you plz help me to understand this part of code:

    for index in 0…arrJSON.count-1

    why you used -1

    Thanks Again.

  • Aravindakumarauro

    how to get “phone”: {

    “mobile”: “+91 0000000000”,

    “home”: “00 000000”,

    “office”: “00 000000”

    } values mobile ,home and phone

  • Ernist Isabekov

    if JSON return with same character? for example “//”