繁体   English   中英

尝试在Swift中使用SwiftyJSON循环时,JSON类型不符合协议SecuenceType

[英]Type JSON does not conform to protocol SecuenceType when trying to loop using SwiftyJSON in Swift

我使用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)
            }
    }

谢谢,我很快就新来了。

文件

for (index: String, el: JSON) in resultados {
    println(el)
}

应该为您工作。 如果失败,则可能需要更新SwiftyJSON。

或者,您可以尝试

for el in resultados.arrayValue {
    println(el)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM