[英]Type JSON does not conform to protocol SecuenceType when trying to loop using SwiftyJSON in Swift
im using SwiftyJSON library to parse my json responses in swift, but Xcode give this error and can't loop the array, here is my code: 我使用SwiftyJSON库快速解析了我的json响应,但是Xcode给出了此错误,并且无法循环该数组,这是我的代码:
Alamofire.request(.GET, "http://li.homeip.net:8091/query/search/", parameters: ["q": self.queryBox.text])
.responseJSON{ (request, response, responseSphinx, error) in
self.spinner.stopAnimating()
self.spinner.alpha = 0
let jsonSphinx = JSON(object: responseSphinx!)
let resultados = jsonSphinx["matches"]
println(resultados[1]["attrs"]["excerpt"]) // this works fine
for el in resultados { // Error: Type JSON does not conform to protocol SecuenceType
println(el)
}
}
Thanks, im new in swift. 谢谢,我很快就新来了。
The documentation says 该文件说
for (index: String, el: JSON) in resultados {
println(el)
}
should work for you. 应该为您工作。 If this fails, you may need to update SwiftyJSON. 如果失败,则可能需要更新SwiftyJSON。
Alternatively, you can try 或者,您可以尝试
for el in resultados.arrayValue {
println(el)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.