SwiftFunction解析JSON并返回字典数组 | 您所在的位置:网站首页 › 转化为字典 › SwiftFunction解析JSON并返回字典数组 |
1> Nirav D..: api调用async(以后台方式)工作,这就是为什么您需要使用swift closure而不是return的原因dictionary。像这样更改代码 func getPlayers(completion: (Array>) -> ())) { var result = [[String:AnyObject]]() Alamofire.request(.GET, "http://example.com/api/v1/players", parameters: ["published": "false"]) .responseJSON { (responseData) -> Void in if((responseData.result.value) != nil) { let respOnse= JSON(responseData.result.value!) if let data = response["data"].arrayObject { print(data) result = data as! [[String:AnyObject]] } } completion(result) } }像这样打电话 self.getPlayers() { (result) -> () in print(result) } |
CopyRight 2018-2019 实验室设备网 版权所有 |