JSON连结:http : //vgmdb.info/album/79?format=json
我尝试过的代码:
$string = file_get_contents("http://vgmdb.info/album/79?format=json");
$json_a=json_decode($string,true);
$getit = $json_a['release_price']['price'];
echo $getit ;
但是我得到一个空白的结果。然后,我尝试下载文件并上传到我的服务器:
$string = file_get_contents("jsonfile.json");
$json_a=json_decode($string,true);
$getit = $json_a['release_price']['price'];
echo $getit ;
其显示价格值。那么如何在不先下载json文件的情况下获取价格值呢?
我在localhost中尝试过,我得到了:
警告:file_get_contents(http://vgmdb.info/album/79?format=json):无法打开流:HTTP请求失败!HTTP / 1.1 500内部服务器错误
这只是一个提示,因此在调试代码时应始终启用错误。
http500
代码是该服务器的内部错误。我只是尝试将User-Agent添加到请求中,并且它的工作原理是:
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"User-Agent: Mozilla/5.0\r\n"
)
);
$string = file_get_contents("http://vgmdb.info/album/79?format=json", false, stream_context_create($options));
$json_a=json_decode($string,true);
$getit = $json_a['release_price']['price'];
echo $getit ;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句