Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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_encode返回NULL,json_last_error_msg给出";控制字符错误,可能编码不正确;_Php_Json - Fatal编程技术网

Php json_encode返回NULL,json_last_error_msg给出";控制字符错误,可能编码不正确;

Php json_encode返回NULL,json_last_error_msg给出";控制字符错误,可能编码不正确;,php,json,Php,Json,当读入我的编辑器时,该文件看起来很好 $file = file_get_contents('path/to/file.json'); $json = json_decode($file, true); var_dump($json); // null echo json_last_error_msg(); //Control character error, possibly incorrectly encoded 关于此错误消息的含义,没有太多说明。您可以删除,PCRE支持字符类的POSI

当读入我的编辑器时,该文件看起来很好

$file = file_get_contents('path/to/file.json');
$json =  json_decode($file, true);
var_dump($json); // null
echo json_last_error_msg(); //Control character error, possibly incorrectly encoded
关于此错误消息的含义,没有太多说明。

您可以删除,PCRE支持字符类的POSIX表示法


你能发布你的
文件.json
?因为
json\u decode
无法从文件中解码json字符串。这意味着您的文件不包含有效的json。通常,这是错误的方法。假设您有以下字符串:“hello\nworld”,其中\n是unscaped(0x0a)char
preg_replace
将修复它,但您仍将使用“helloworld”。应该修复生成json编码字符串的代码。
$json = preg_replace('/[[:cntrl:]]/', '', $json);
$json = json_decode($json, true);
var_dump($json);
echo json_last_error_msg();