Resolve PHP json decode error

From LemonWiki共筆
Jump to: navigation, search

Syntax error, malformed JSON[edit]

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[edit]

Possible causes

Solution:

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

References[edit]

Relates articles[edit]