php json_decode
无法解码“ []”
$json = file_get_contents(__DIR__ . '/wrong_empty.json');
echo "content: " . $json, "\n"; //"content: []"
echo "encoding: " . mb_detect_encoding($json) . "\n"; //"encoding: UTF-8"
//$json = mb_convert_encoding($json, 'UTF-8');
$a = json_decode($json);
echo json_last_error_msg()."\n"; //"Syntax error"
看起来来自以“ efbb bf”十六进制开头的文件的编码:
~/workspace/jsonerror$ xxd fine_empty.json
00000000: 5b5d []
~/workspace/jsonerror$ xxd wrong_empty.json
00000000: efbb bf5b 5d ...[]
要在计算机上复制:https://github.com/remmel/jsonerror
php -v
:PHP 7.3.7-1+ubuntu18.10.1+deb.sury.org+1 (cli) (built: Jul 10 2019 06:55:06) ( NTS )