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)charpreg_replace
将修复它,但您仍将使用“helloworld”。应该修复生成json编码字符串的代码。
$json = preg_replace('/[[:cntrl:]]/', '', $json);
$json = json_decode($json, true);
var_dump($json);
echo json_last_error_msg();