我正在使用图形请求通过以下代码获取 json:
nextrequest.start({ (response: HTTPURLResponse?, result: Any?) in
print(result)
})
这是下面的 json result
,我不知道如何访问其中的数据,例如性别、ID 和姓名...
Optional(FacebookCore.GraphRequestResult<FacebookCore.GraphRequest>.success(FacebookCore.GraphResponse(rawResponse: Optional({
gender = male;
id = 1128614937219535;
name = "Rayan Slim";
picture = {
data = {
height = 320;
"is_silhouette" = 0;
url = "https://scontent.xx.fbcdn.net/v/t1.0-1/p320x320/12541113_961418627272501_5451131278168499090_n.jpg?oh=47433bc236ce63ce1c07b92499087f29&oe=586A406A";
width = 320;
};
};
}))))
任何帮助将不胜感激!!!!
最佳答案
在授予权限后,这里的功能就可以工作了。
if AccessToken.current != nil {
GraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start({ (urlResponse, requestResult) in
switch requestResult {
case .Success(let response):
if let responseDictionary = response.dictionaryValue {
let email = responseDictionary["email"] as? String
print(email)
let first = responseDictionary["name"] as? String
print(first)
if let picture = responseDictionary["picture"] as? NSDictionary {
if let data = picture["data"] as? NSDictionary{
if let profilePicture = data["url"] as? String {
print(profilePicture)
}
}
}
}
case .Failed(let error):
print(error)
}
})
}
关于ios - 如何从 swift 3 facebook 图形请求中解析这个 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39717002/