from this link我得到了相同的 commonName 但它应该是不同的?!
let jsonData = NSData(contentsOfURL: url!)
let readableJSON = JSON(data: jsonData!, options: NSJSONReadingOptions.MutableContainers, error: nil)
let object = try! NSJSONSerialization.JSONObjectWithData(jsonData!, options: NSJSONReadingOptions.AllowFragments) as! Dictionary<String, AnyObject>
let json = JSON(object)
for (_,object):(String, JSON) in readableJSON {
let commonName = json["toLocationDisambiguation"]["disambiguationOptions"][0]["place"]["commonName"].stringValue
commonNameArray.append(commonName)
}
最佳答案
因为 [0],你需要做一些类似的事情
var i = 0
for (_,object):(String, JSON) in readableJSON {
let commonName = json["toLocationDisambiguation"]["disambiguationOptions"][i]["place"]["commonName"].stringValue
commonNameArray.append(commonName)
i = i+1
}
关于json - 为什么我的 commonName 在我的循环中重复相同的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35582252/