Alamofire.request(webpath).responseJSON
{ response in
//here check success key ???
}
my json response contains
{Message = "some message";
Success = True;}
how to take Success key directly from response and check in if condition ? that it is true or false
Result
object from the response. It is an enum that can either be success
or failure
.Any
object returned from the success
value as a dictionary.Like following:
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
}
}