我调试了我的代码,它从我的JSON输出了正确的数组,但是,我得到了致命的错误:
数组索引超出范围
这是我的代码:
var commonNameArray = [String]()
let jsonData = NSData(contentsOfURL: url!)
let readableJSON = try! NSJSONSerialization.JSONObjectWithData(jsonData!, options: []) as! [String:AnyObject]
let object = JSON(readableJSON)
let disambiguationOptions = object["toLocationDisambiguation"]["disambiguationOptions"]
for option in disambiguationOptions.arrayValue {
let commonName = option["place"]["commonName"].stringValue
commonNameArray.append(commonName)
}
NumberOfRows = commonNameArray.count