码迷,mamicode.com
首页 > Web开发 > 详细

jSON Call can throw but it is not marked with try

时间:2015-12-14 21:18:15      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

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
}

第二种用法:

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

jSON Call can throw but it is not marked with try

标签:

原文地址:http://www.cnblogs.com/luoxiaoxi/p/5046484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!