我在我的存储中的一个文件中有一个很大的Json数据,我正在尝试使用SwiftyJson解析那个json。这是我的代码:
let path = NSBundle.mainBundle().pathForResource("ostan_city", ofType: "JSON")!
do {
let jsonDta = try NSData(contentsOfURL: NSURL(fileURLWithPath: path), options: NSDataReadingOptions.DataReadingMappedIfSafe)
let json = JSON(data: jsonDta)
for item in json["ostan"].arrayValue {
var citiesArray = [city]()
for cities in item["cities"].arrayValue {
citiesArray.append(city(id: cities["id"].stringValue , name: cities["name"].stringValue ))
}
ostans.append(ostan(id: item["id"].stringValue, name: item["name"].stringValue , cities: citiesArray) )
citiesArray = []
}
}catch {
}我已经对它进行了调试,path和jsonDta都有值,但是在JSON方法运行之后,它里面没有值,swiftyJson也没有返回任何值。
有什么问题吗?这是从nsbundle中获取json的正确方式吗?
谢谢
发布于 2015-12-27 00:23:36
您的代码没有问题。问题出在你的ostan_city.JSON中,它不是JSON格式的。
https://stackoverflow.com/questions/34469223
复制相似问题