json_decode('["foo","bar"]', true)
,这个工程,但这个返回NULL
,json_decode("['foo','bar']", true)
。 json_last_error()
输出4
,JSON_ERROR_SYNTAX
。json_decode返回null与不同的qoute
我检查了以下问题的一些答案;
json_decode() returns null issues
PHP json_decode() returns NULL with valid JSON?
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']"
转换为'["foo","bar"]'
作为解决方法?
的字符串的功能'json_decode'作为一个参数需要是有效的JSON。 '{“a”:1,“b”:2,“c”:3,“d”:4,“e”:5}'这是有效的JSON。你只是传入一个用引号括起来的数组。 – sidneydobber