在swift 3中获得[String:AnyObject]的更深嵌套值

时间:2016-12-14 19:17:29

标签: swift3

我通过Firebase Facebook身份验证登录用户来获取用户的Facebook个人资料详情。

嵌套数组如下所示:

 ["picture": { 
     data = {
        "is_silhouette" = 0;
        url = "someUrl"; 
    };
}, "name": James, "last_name": Bond, "email": james_bond007@hotmail.com, "id": 10210066243726102, "first_name": James, "gender": male]

我正在努力获得图片网址的价值。

我尝试过类似的东西,但它不起作用:

var fbPhotoUrl: URL?
self.fbPhotoUrl = self.FBUserDict["picture"]!["data"]!["url"] as? URL

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

if let picture = FBUserDict["picture"] as? [String: Any], let data = picture["data"] as? [String: Any], let urlString = data["url"] as? String, let url = URL(string: urlString) {

    self.fbPhotoUrl = url
}