我是 Swift 和 JSON 的新手,需要一些快速帮助。我的应用程序有 Facebook 身份验证,并且会读取已授权该应用程序的 friend 列表。一切都正确记录,但我不熟悉如何打印每个 friend 的 friend ID。这是我的代码:
FBSDKGraphRequest(graphPath: "me",
parameters: ["fields": "id, name,friends, first_name, last_name, picture.type(large), email"])
.start(completionHandler: { (connection, result , error) -> Void in
let data:[String:AnyObject] = result as! [String : AnyObject]
print(data)
这是它为 friend 记录的数据:
"friends": {
data = (
{
id = 10104542348623278;
name = "John Smith";
},
但我不知道如何打印每个 friend 的 ID。这是我试过不成功的。
for friend in data["friends"] {
let friendId = data["friends"]["id"]
print(friendId)
}
任何帮助将不胜感激。
最佳答案
friends
是一个字典。data
里面是一个Dictionary数组。if let friendsData = data["friends"] as? [String:AnyObject] { if let friends = friendsData["data"] as? [[String:AnyObject]] { for friend in friends{ print(friend["id"]) } } }
关于ios - 从 Facebook JSON 访问好友数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39902902/