Resolve PHP json decode error: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
Line 30: Line 30:
* [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://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]


[[Category:Data Science]] [[Category:PHP]] [[Category:Json]] [[Category:Text file processing]]
[[Category:Data Science]] [[Category:PHP]] [[Category:Json]] [[Category:Text file processing]]

Revision as of 11:39, 23 April 2019

Syntax error, malformed JSON

Possible causes

  • the input is empty entirely or multiple white spaces
  • the input contains Byte order mark (BOM)[1]
  • Use ' instead of " for quotation

Solution:

Unexpected control character found

Possible causes

Solution:

  • Remove control character. Using PHP:
$replacement = '';
preg_replace('/[\x00-\x1F]/', $replacement, $input);

References

Relates articles