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