json_decode()返回空,但它是有效的json

时间:2021-07-15 20:29:45
$a = '[{"function":"error_handler","class":"LP","type":"::","args":[256,"Call to undefined method LP_pdo::get_rorzxx() on D:\\MARK\\htdocs\\lessphptest\\application\\controllers\\users.php (23)","D:\\MARK\\htdocs\\lessphp\\LP.php",210,{"e":{"type":1,"message":"Call to undefined method LP_pdo::get_rorzxx()","file":"D:\\MARK\\htdocs\\lessphptest\\application\\controllers\\users.php","line":23}}]},{"file":"D:\\MARK\\htdocs\\lessphp\\LP.php","line":210,"function":"trigger_error","args":["Call to undefined method LP_pdo::get_rorzxx() on D:\\MARK\\htdocs\\lessphptest\\application\\controllers\\users.php (23)",256]},{"function":"shutdown","class":"LP","type":"::","args":[]}]';
$a = json_decode($a);
print_r($a);

echo json_last_error();

print_r() returns blank.

print_r()返回空白。

json_last_error() returns 4 which is JSON_ERROR_SYNTAX

json_last_error()返回4,这是JSON_ERROR_SYNTAX

But, when I run the json string in http://jsonlint.com/ it returns Valid JSON

但是,当我在http://jsonlint.com/中运行json字符串时,它会返回有效的json

Any ideas why?

任何想法为什么?

2 个解决方案

#1


12  

You need to escape your \ once for PHP and once again for JSON

您需要转义PHP和JSON的\一次

D:\\\\....

D:\ \ \ \ ....

#2


0  

Try to set encoding to utf-8...did the job for me

尝试将编码设置为utf-8…这工作是为我做的吗?

#1


12  

You need to escape your \ once for PHP and once again for JSON

您需要转义PHP和JSON的\一次

D:\\\\....

D:\ \ \ \ ....

#2


0  

Try to set encoding to utf-8...did the job for me

尝试将编码设置为utf-8…这工作是为我做的吗?