【发布时间】:2015-02-14 11:50:53
【问题描述】:
我正在尝试从 iOS 中的 JSON 文件中获取 JSON 数组。问题是代码不起作用 JSON文件内容为:
[{a:"m",data:"1597,144",tick:1},{a:"m",data:"1595,144",tick:1}, ...]
这是我的 Swift 代码:
if let filePath = NSBundle.mainBundle().pathForResource("data", ofType: "json") {
let array = NSMutableArray(contentsOfFile: filePath)
println("\(array)")
}
该文件存在于路径中,但由于某种原因它无法正常工作。当我尝试打印数组时,我得到null。
【问题讨论】:
-
来自文档:
aPath The path to a file containing a representation of an array produced by the writeToFile:atomically: method.也就是说 - 它只读取以这种方式创建的文件,而不是任意文本文件。 -
谢谢您的回复,如果我想实现这个功能,我该怎么做? @Grimxn