简体   繁体   English

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

[英]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.

相关问题 类型不符合协议Swift - Type does not conform to protocol Swift Swift - 类型“*”不符合协议“*” - Swift - Type '*' does not conform to protocol '*' 类型不符合协议序列类型 - Swift - type does not conform to protocol Sequence Type - Swift 类型“NSPersistentStore”在swift中不符合协议“BooleanType” - Type 'NSPersistentStore' does not conform to protocol 'BooleanType' in swift Swift:类型'ViewController'不符合协议'UIPageViewControllerDataSource' - Swift: Type 'ViewController' does not conform to protocol 'UIPageViewControllerDataSource' Swift 2.0类型'()'不符合协议 - Swift 2.0 Type '()' does not conform to protocol Swift:`类型'[String]'不符合协议'StringLiteralConvertible' - Swift: `Type '[String]' does not conform to protocol 'StringLiteralConvertible'` 类型“myViewController”不符合Swift中的协议UIPIckerDataSource - Type “myViewController” does not conform to protocol UIPIckerDataSource in Swift Swift - MultipeerConnectivity类型不符合协议 - Swift - MultipeerConnectivity Type does not conform to protocol Swift-类型'MenuViewController'不符合协议'GKGameCenterControllerDelegate' - Swift - Type 'MenuViewController' does not conform to protocol 'GKGameCenterControllerDelegate'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM