Alamofire.request(webpath).responseJSON
{ response in
//here check success key ???
}
我的json响应包含
{Message = "some message";
Success = True;}
如何直接从响应获取成功密钥并在条件下签入?它是真还是假
答案 0 :(得分:1)
您可以按以下方式进行检查:
let statusCheck = dicObj["Success"] as! Int
if statusCheck == 1{
println("Success")
}
else{
println("Failure")
}
答案 1 :(得分:1)
您可以像这样检索。
if let result = response.result.value {
let JSON = result as! [String:Any]
if JSON["success"] == 1
{
print("success")
}
}
答案 2 :(得分:1)
Result
对象。这是一个枚举,可以是success
或failure
。Any
值返回的success
对象转换为字典。如下:
Alamofire.request(webpath).responseJSON { response in
guard case .success(let rawJSON) = response.result else {
// handle failure
return
}
// rawJSON is your JSON response in an `Any` object.
// make a dictionary out of it:
guard let json = rawJSON as? [String: Any] else {
return
}
// now you can access the value for "Success":
guard let successValue = json["Success"] as? String else {
// `Success` is not a String
return
}
if successValue == "True" {
// do something
} else {
// do something else
}
}