php:在googleappengine上解析json
我使用下面的代码获取一个url,它工作成功,返回一个json数据php:在googleappengine上解析json,php,json,google-app-engine,facebook-graph-api,Php,Json,Google App Engine,Facebook Graph Api,我使用下面的代码获取一个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;
$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代码
{
我不能在GAE上使用json解码,当我尝试json解码时,我发现服务器错误,是否有其他方法在php上解析它,请帮助我。1。确保json解码存在(已启用)
2.使用try-catch捕获解析错误
<?php
try {
$response = json_decode($friends, true);
print_r($response);
} catch (Exception $ex) {
echo 'Caught exception: ', $ex->getMessage(), "<br/>\n";
var_dump($friends);
}
?>
3.在上阅读更多信息,如果函数正常,也尝试在此处验证JSON响应。 我试过贴的,看起来有效。
但是出于安全原因,我建议您可能会更改某些内容。哪个错误?发布所有详细信息。如果我添加行$data=json\u decode($friends,true),我只会收到谷歌服务器错误;你是如何在AppEngine上运行PHP的?它是Python、Java和Go only。正如他在对我的代码的评论中所说的,他正在得到NULL。因此JSON可能是错误的,因此我给你一个+1!它不是错误的…我得到的输出类似于stdClass对象([education]=>Array([0]=>stdClass对象……)。。。。。。。。
<?php
if (function_exists('json_decode')) {
echo "json_decode functions is available.<br />\n";
} else {
echo "json_decode functions is not available.<br />\n";
}
?>
<?php
try {
$response = json_decode($friends, true);
print_r($response);
} catch (Exception $ex) {
echo 'Caught exception: ', $ex->getMessage(), "<br/>\n";
var_dump($friends);
}
?>