如果json数据成功= true,我只想移动到下一个控制器

时间:2018-01-04 12:19:48

标签: json swift

根据Json数据,如果json data (success = true),那么我只想将用户移动到下一个View Controller。

{
 "success": true,
    "message": "Loged In",
    "User_details": {
        "user_id": "208",
        "user_name": "Samad",
        "phone": "9705994458",
        "email": "laddafsamad.12@gmail.com",
        "image": "https://laex.in/testprep/Dashboard/uploads/user/1499063695.jpg"
    }
}

2 个答案:

答案 0 :(得分:0)

if let responce = yourJson as? [String: Any],
   let isSuccess = responce["success"] as? Bool,
   isSuccess {
     // Send user to next viewcontroller
}

试试这段代码:)

答案 1 :(得分:0)

let result : NSDictionary! = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! NSDictionary

if let success = result.value(forKey: "success") as? Bool {

  if success {
    // navigate to next viewcontroller
  }

}