如何在警报中显示响应消息?

时间:2018-04-02 13:09:38

标签: ios json swift alamofire uialertview

我想将响应消息显示为警告消息。我的代码如下:

parameters["FName"] = txtFirstName.text ?? ""
parameters["LName"] = txtLastName.text ?? ""
parameters["Email"] = txtEmailId.text ?? ""
parameters["Mobile"] = txtMobileNumber.text ?? ""
parameters["Password"] = txtPassword.text ?? ""
Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.httpBody, headers: nil).responseJSON {
            (response) in
            print(response.result.value!)
        }

我的回复信息是......

{
    message = "Registered Successfully!";
    result = True;
}

我想展示" message"的价值。键。请提前帮助我。

2 个答案:

答案 0 :(得分:1)

 if let result = response.result.value,  let JSON = result as! [String: Any] {

print(JSON["message"]as? String)

let alert = UIAlertController(title: "congrats", message: JSON["message"]as? String, preferredStyle: .alert)

    alert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))

    self.present(alert, animated: true)

     }

或使用this库提前通知消息

self.showMessage(JSON["message"]as? String, type: .success) //.success mean green color alert

答案 1 :(得分:1)

if let responseDict = response.result.value as? [String: Any], let msg = responseDict["message"] as? String  {


         //show alert here....

}