How to access nested JSON in brackets in Swift?

前端 未结 2 1996
無奈伤痛
無奈伤痛 2021-01-26 04:52

I have a JSON response which is in brackets and I struggle to access the inner fields e.g. display_name with Swift. How can I do that?

Optional([\"result\": {
us         


        
2条回答
  •  礼貌的吻别
    2021-01-26 05:39

    1-Get the result object from response
    2-Get the user object from result object
    3-Get the user info as String from user object .

    let response = responseObject as? [String: AnyObject]
    let result = response!["result"]  as? [String: AnyObject]
    
    if let user = result!["user"]  as? [String: AnyObject] {
            let displayName = user["display_name"] as? String
            let email = user["email"] as? String
    }
    

提交回复
热议问题