-1
var err: NSError?
var json = JSONSerialization.JSONObjectWithData(data!, options: .MutableContainers, error: &err) as? NSDictionary

it shows the error in 2nd line as "Extra argument 'error' in call"

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Murali Krishnan
  • 272
  • 5
  • 20
  • 3
    That looks a lot like Swift 2 code. You should find a tutorial written in at least Swift 3, otherwise you are wasting your time. – rmaddy Sep 20 '19 at 06:56
  • [This](https://developer.apple.com/documentation/foundation/jsonserialization/1415493-jsonobject) is how that method looks today – Joakim Danielson Sep 20 '19 at 07:14
  • Refer this link https://stackoverflow.com/questions/26840736/converting-json-to-nsdata-and-nsdata-to-json-in-swift – user1482953 Sep 20 '19 at 07:34

1 Answers1

0

You should check firstly if the error occurs instead of making serialization

do {
    let jsonObject = try JSONSerialization.jsonObject(with: jsonData)
    guard let dictionary = jsonObject as? Dictionary<String, Any> else {
        print("Not a Dictionary")
        // put in function
        return
    }
    print("JSON Dictionary! \(dictionary)")
}
catch let error as NSError {
    print("Found an error - \(error)")
}