Issue with Swift 2 Error Handling

后端 未结 1 1491
梦毁少年i
梦毁少年i 2021-01-14 00:59

I am using REST to get JSON data and then parse it. To do this I am using NSJSONObjectWithData, as far as I\'m aware this method used to have an error handler within its par

相关标签:
1条回答
  • 2021-01-14 01:27

    Here is the correct implementation,

    do {
        let jsonDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
    
        //Use your dictionary here.
        print("JSON : \(jsonDictionary)")
    }
    catch  {
        print(error)
        //Handle any error.
    }
    
    0 讨论(0)
提交回复
热议问题