【发布时间】:2016-11-25 18:37:27
【问题描述】:
当我尝试运行这个项目时,我遇到了“使用未解决的标识符错误”。这是我得到错误的代码
var jsonDict = 试试 NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) 作为! NSDictionary 让任务:NSURLSessionDataTask = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in 如果((错误)!=零){ 打印(错误!.localizedDescription) } 别的 { 让错误:NSError? 做 { var jsonDict = 试试 NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NS词典 } 抓住 { 如果(错误!=零){ print("JSON 错误 \(err!.localizedDescription)") } 别的 { //5: 提取引号和值并在 NSNotification 中发送它们 让引号:NSArray = ((jsonDict.objectForKey("query") as!NSDictionary).objectForKey("results") as!NSDictionary).objectForKey("quote") as! NSArray dispatch_async(dispatch_get_main_queue(), { NSNotificationCenter.defaultCenter().postNotificationName(kNotificationStocksUpdated, object: nil, userInfo: [kNotificationStocksUpdated:quotes]) }) } } } })有人可以帮忙吗?谢谢。
【问题讨论】:
-
你在哪一行得到错误?
-
是的,它出现在哪一行?
-
@WMios 我刚刚更新了代码以显示错误的位置
-
@LinkOpenheim 我刚刚更新了代码以显示错误的位置
-
你定义了你的
data!NSData类型吗?
标签: ios swift debugging error-handling