我使用下面的代码来获取一个 url,这成功了,它返回一个 json 数据
$url = "https://graph.facebook.com/me?access_token=".$access_token;
function fetch_url($url){
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
$java_url = new URL($url);
$java_bufferreader = new BufferedReader(new InputStreamReader($java_url->openStream()));
while (($line = $java_bufferreader->readLine()) != null) {
$content .= $line;
}
return $content;
}
// Sample usage:
$friends = fetch_url($url);
当我回显 $friends 时,我得到以下 json 代码,
{
"id": "100003185423323",
"name": "hnu Chid",
"first_name": "hnu",
"last_name": "Chid",
"link": "http://www.facebook.com/ilovaddddd",
"username": "ilddddd",
"education": [
{
"school": {
"id": "182225911846032",
"name": "Sunean"
},
"type": "High School"
},
{
"school": {
"id": "105504952817559",
"name": "Sathya University"
},
"type": "College"
}
],
"gender": "female",
"timezone": 5.5,
"locale": "en_US",
"verified": true,
"updated_time": "2012-09-18T18:37:57+0000"
}
我不能在 GAE 上使用 json 解码,当我尝试 json 解码时出现服务器错误,有没有其他方法可以在 php 上解析它,请帮助我。