我在最新版本的Xcode,我得到这个错误:“从'NSData'投射?'无关型 '的NSDictionary' 总是失败”Swift - 从'NSData'投射?到无关的类型'NSDictionary'总是失败
与此代码:
let dataObject = NSData(contentsOfURL: location)
let weatherDictionary: NSDictionary = NSJSONSerialization.dataWithJSONObject(dataObject!, options: nil, error: nil) as! NSDictionary
编程语言:雨燕
更新的代码:
if (error == nil) {
let dataObject = NSData(contentsOfURL: location)
let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as! NSDictionary
}
- 得到一个断点现在,当我运行我的应用。
对不起,我还是新堆栈溢出
是的,它是NSDictionary –
'let weatherDictionary:AnyObject! = NSJSONSerialization.JSONObjectWithData(dataObject,options:NSJSONReadingOptions.MutableContainers,error:nil)'使用此代码并检查'weatherDictionary'是'NSArray'或'NSDictionary'。 –
仍然出错 –