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)")
}
来源:oschina
链接:https://my.oschina.net/dong706/blog/4497565