Alamofire 5 GET 请求,解析返回JSON

假如想象 提交于 2020-08-16 14:04:18

Alamofire 5 GET 请求,解析返回JSON

 struct Login: Encodable {
           let userCode: String
           let password: String
        }

       let login = Login(userCode: userCode!, password: password!)

       AF.request(serviceUrl+"/pub/login/submit",
                  method: .get,
                  parameters: login
                  //encoder: JSONParameterEncoder.default
       ).responseJSON { response in

        //print(response.result)
        
        switch response.result {
               case .success(let JSON):
                   print("Success with JSON: \(JSON)")
                   let dict = JSON as! Dictionary<String,AnyObject>
                   let code = dict["code"] as! String
                   let data = dict["data"] as! String
                   let message = dict["message"] as! String
                   print(message)
               case .failure(let error):
                   print("Request failed with error: \(error)")
        }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!