Created
September 19, 2014 08:25
-
-
Save hnq90/31c53e58eaa8686e1f17 to your computer and use it in GitHub Desktop.
Detect Json ecode error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$json = json_encode($output); | |
switch (json_last_error()) { | |
case JSON_ERROR_NONE: | |
echo ' - No errors'; | |
break; | |
case JSON_ERROR_DEPTH: | |
echo ' - Maximum stack depth exceeded'; | |
break; | |
case JSON_ERROR_STATE_MISMATCH: | |
echo ' - Underflow or the modes mismatch'; | |
break; | |
case JSON_ERROR_CTRL_CHAR: | |
echo ' - Unexpected control character found'; | |
break; | |
case JSON_ERROR_SYNTAX: | |
echo ' - Syntax error, malformed JSON'; | |
break; | |
case JSON_ERROR_UTF8: | |
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; | |
break; | |
default: | |
echo ' - Unknown error'; | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment