Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP不使用'转换JSON;json#u decode()';_Php_Json - Fatal编程技术网

PHP不使用'转换JSON;json#u decode()';

PHP不使用'转换JSON;json#u decode()';,php,json,Php,Json,我有一个非常简单的代码 $pc1 = $_POST['post_code1']; $pc2 = $_POST['post_code2']; $url = "http://maps.google.com/maps/nav?q=from:".$pc1."%20to:".$pc2; $url_data = file_get_contents($url); $json_data = json_decode($url_data); var_dump($json_data); $url\u data充满了

我有一个非常简单的代码

$pc1 = $_POST['post_code1'];
$pc2 = $_POST['post_code2'];
$url = "http://maps.google.com/maps/nav?q=from:".$pc1."%20to:".$pc2;
$url_data = file_get_contents($url);
$json_data = json_decode($url_data);
var_dump($json_data);

$url\u data
充满了有趣的json内容,但是
$json\u data
返回
NULL
。有人知道为什么吗?

在找到许多有类似问题的人后,我发现以下方法有效

$json_data = json_decode(utf8_encode($url_data),true);

您确定其中包含完全有效的JSON吗?URL是否通过验证?它有多深?PHP文档:“如果json无法解码或编码数据深度超过递归限制,则返回NULL。”递归限制默认为512。
var\u dump($url\u data)
?可能是禁用的?不,我让我的提供程序在
php.ini中启用
fopen()
,这是正确的,因为
file\u get\u contents
是逐字节执行的,而不是逐字符执行的。