Swift 2 jSON Call can throw but it is not marked with try

前端之家收集整理的这篇文章主要介绍了Swift 2 jSON Call can throw but it is not marked with try前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

yesterday i updated to El Capitan beta 2 and Xcode 7 - beta is mandatory. So i updated my app to Swift 2 and new error comes to the json string. This is my code :

let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!,options:NSJSONReadingOptions.MutableContainers ) as! NSDictionary


第一种用法

do {
   let jsonData = try NSJSONSerialization.JSONObjectWithData(urlData!,options:NSJSONReadingOptions.MutableContainers ) as! NSDictionary
   // use jsonData
} catch {
    // report error
}
第二种用法

letjsonData = try NSJSONSerialization.JSONObjectWithData(urlData!,options:NSJSONReadingOptions.MutableContainers ) as! NSDictionary

猜你在找的Swift相关文章