我正在尝试从URL(json文件)获取数据我在这些行上得到此错误:
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as! NSDictionary
if (err != nil) {
println("JSON Error \(err!.localizedDescription)")
}
Run Code Online (Sandbox Code Playgroud)
错误说
线程6:信号SIGABIRT - 无法将类型'__NSArrayM'(0x518b58)的值转换为'NSDictionary'(0x518d74).
我很确定.count返回数组的长度,但出于某种原因,当我使用它时,它会引发一个奇怪的错误.
继承我的代码:
let dataFile = NSBundle.mainBundle().pathForResource(RopeDataFile, ofType: nil)
let ropes = NSArray(contentsOfFile: dataFile!);
for i in 0..<ropes.count {
}
Run Code Online (Sandbox Code Playgroud)
RopeDataFile 是我之前制作的属性列表的常量.
出于某种原因,它会出现此错误ropes.count,
'NSArray的?' 没有名为'count'的成员.
如果问题非常简单,我很快就会对此表示不满.
帮助我在Swift中选择地狱.如何返回键"R"的数组计数.self.jsonObj可以为null
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return (self.jsonObj["R"]! as? NSArray)?.count;
}
Run Code Online (Sandbox Code Playgroud)