SwiftFunction解析JSON并返回字典数组 您所在的位置:网站首页 转化为字典 SwiftFunction解析JSON并返回字典数组

SwiftFunction解析JSON并返回字典数组

2023-03-09 21:11| 来源: 网络整理| 查看: 265

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 实验室设备网 版权所有