【发布时间】:2015-05-01 07:21:29
【问题描述】:
我在我的文件系统中添加了一个 JSON 文件,其中数据的结构如下:
{ “DDD”:“3D Systems Corporation”,“MMM”:“3M 公司”,“WBAI”: “500.com Limited”、“WUBA”:“58.com Inc.”、“AHC”:“A.H. Belo Corporation”、“ATEN”:“A10 Networks, Inc.”、“AAC”:“AAC Holdings、 Inc.”、“AIR”:“AAR Corp.”}
我的文件名是 stockDict.json,我正在尝试使用以下代码从中检索数据:
let jsonFilePath:NSString = NSBundle.mainBundle().pathForResource("stockDict", ofType: "json")!
let jsonData:NSData = NSData.dataWithContentsOfMappedFile(jsonFilePath as String) as! NSData
let error:NSError?
let json = JSON(jsonData)
println(json[0][0].string)
但是当它打印出来时我得到的只是nil。我的代码有什么问题?
任何建议将不胜感激。
【问题讨论】:
-
我发现这个答案很有帮助stackoverflow.com/a/28644494/535339
标签: json swift swifty-json