【问题标题】:if json data success = true only i want to move to next controller如果 json data success = true 只有我想移动到下一个控制器
【发布时间】:2018-01-04 12:19:48
【问题描述】:

根据 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"
    }
}

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 发布您的代码,以便我们为您提供帮助。

标签: json swift


【解决方案1】:
if let responce = yourJson as? [String: Any],
   let isSuccess = responce["success"] as? Bool,
   isSuccess {
     // Send user to next viewcontroller
}

试试这个代码:)

【讨论】:

  • 如果您分享您到目前为止尝试过的代码,那么解决您的问题会容易得多。
【解决方案2】:
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
  }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 2017-01-08
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多