Resolve PHP json decode error: Difference between revisions

Jump to navigation Jump to search
m
 
(7 intermediate revisions by one other user not shown)
Line 2: Line 2:
== Syntax error, malformed JSON ==
== Syntax error, malformed JSON ==
Possible causes
Possible causes
* the input is empty or multiple white spaces
* the input is empty entirely or combination of multiple white spaces
* the input contains [[Byte order mark]] (BOM)<ref>[https://blog.longwin.com.tw/2013/11/php-json_decode-null-fix-2013/ PHP json_decode() 傳回 NULL 的解法 | Tsung's Blog]</ref>
* the input contains [[Byte order mark]] (BOM)<ref>[https://blog.longwin.com.tw/2013/11/php-json_decode-null-fix-2013/ PHP json_decode() 傳回 NULL 的解法 | Tsung's Blog]</ref>
* One file was combined with multiple JSON which were separated by return symbol
* Use {{kbd | key=<nowiki>'</nowiki>}} instead of {{kbd | key=<nowiki>"</nowiki>}} for quotation


Solution:
Solution:
* Not allowed empty input
* Not allowed empty input
* Remove [[Byte order mark]] (BOM)
* Remove [[Byte order mark]] (BOM)
* Use {{kbd | key=<nowiki>"</nowiki>}} for quotation
* Use [https://jsonlint.com/ JSONLint - The JSON Validator] to validate the JSON format
* Use [https://jsonlint.com/ JSONLint - The JSON Validator] to validate the JSON format


Line 27: Line 30:
== Relates articles ==
== Relates articles ==
* [https://www.php.net/function.json_last_error PHP: json_last_error - Manual]
* [https://www.php.net/function.json_last_error PHP: json_last_error - Manual]
* [https://php.net/manual/en/function.json-last-error.php PHP: json_last_error - Manual]
* [https://github.com/Seldaek/jsonlint Seldaek/jsonlint: JSON Lint for PHP]
* [https://www.php.net/manual/en/class.jsonexception.php PHP: JsonException - Manual] (PHP 7.3.0)


[[Category:Data Science]] [[Category:PHP]] [[Category:Json]] [[Category:Text file processing]]
[[Category:Data Science]] [[Category:PHP]] [[Category:Json]] [[Category:String manipulation]]
Anonymous user

Navigation menu