How to get the result value of Alamofire.request().responseJSON in swift 2?

后端 未结 3 1798
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 14:28

I have a question about the new version of Alamofire for Swift 2

Alamofire.request(.POST, urlString, parameters: parameters as? [String : AnyObject])
                


        
3条回答
  •  鱼传尺愫
    2020-12-08 14:43

    If you don't mind using SwiftyJSON library, here's a working example in Xcode 7 Beta 5 + Alamofire 2.0.0-beta.1 + SwiftyJSON (xcode7 branch)

    Alamofire.request(.GET, url, parameters: params, encoding: ParameterEncoding.URL).responseJSON { (_, _, result) in
        switch result {
            case .Success(let data):
                let json = JSON(data)
                let name = json["name"].string
            case .Failure(_, let error):
                print("Request failed with error: \(error)")
        }
    }
    

    Edit:

    Updated SwiftyJSON git page

提交回复
热议问题