json_decode('["foo","bar"]', true)
,这有效,但是这个返回NULL
, json_decode("['foo','bar']", true)
. The json_last_error()
输出4
, JSON_ERROR_SYNTAX
.
我检查了以下问题的一些答案;
json_decode() 返回 null 问题 https://stackoverflow.com/questions/3110487/json-decode-returns-null-issues
PHP json_decode() 返回 NULL 和有效的 JSON? https://stackoverflow.com/questions/2410342/php-json-decode-returns-null-with-valid-json
json_decode 在 Web 服务调用后返回 NULL https://stackoverflow.com/questions/689185/json-decode-returns-null-after-webservice-call
并尝试了以下解决方案但没有成功;
json_decode(str_replace('"', '"', "['foo','bar']"), true)
json_decode(stripslashes(str_replace('\"', '"', "['foo','bar']")), true)
json_decode(stripslashes("['foo','bar']"), true)
json_decode(utf8_encode("['foo','bar']"), true)
我认为这与 UTF-8 bom 无关。这是 PHP 的错误吗?或者我该怎么转"['foo','bar']"
into '["foo","bar"]'
作为解决方法?