如何获取php中的json返回值? [英] how to grab the json returned value in php?
本文介绍了如何获取php中的json返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Facebook应用程序中有一个脚本,该脚本将在下拉列表中为用户提供他的Facebook朋友列表.使用下面的代码,我可以抓住用户的朋友,但是我只获得用户ID.
I have a script in my facebook application which will provide the user with the list of his Facebook friends in a dropdown list. With the code below, I am able to grab the user's friends, but I am only getting the User ID.
$api_key = 'xxx';
$secret = 'xxx';
include_once 'facebook.php';
$facebook = new Facebook($api_key, $secret);
$friends = $facebook->api_client->friends_get();
foreach ($friends as $friend)
{
echo $friend;// returns only the friend's ID and not name but i want to show the name
$url="https://graph.facebook.com/".$friend."/";
$res=file_get_contents($url);
}
使用此链接,我想获取用户名并将其显示在下拉列表中.我该如何抓取它并仅回显$url
中的名称?
With this link I want to grab the user's name and display it on a dropdown list. How can I grab it and echo only the name from $url
?
{
"id": "4",
"name": "Mark Zuckerberg",
"first_name": "Mark",
"last_name": "Zuckerberg",
"link": "http://www.facebook.com/zuck",
"gender": "male",
"locale": "en_US"
}
推荐答案
$var = json_decode ( $result );
并回显您想要的内容,例如:echo $var ['link'];
and echo what you want, like: echo $var ['link'];
这篇关于如何获取php中的json返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文