json_last_error
Return the last error
json_last_error()
function returns the last error that occurred.
Returns the last error:
<?php // Invalid json string $string = "{'Bill':35,'Elon':37,'Joe':43}" ; echo "Decoding: " . $string ; json_decode ( $string ) ; echo "<br>Error:" ; switch ( json_last_error ( ) ) { case JSON_ERROR_NONE : echo "No error" ; break ; case JSON_ERROR_DEPTH : echo "Exceeding maximum stack depth" ; break ; case JSON_ERROR_STATE_MISMATCH : echo "Invalid or malformed JSON" ; break ; case JSON_ERROR_CTRL_CHAR : echo "Control character error" ; break ; case JSON_ERROR_SYNTAX : echo "grammatical error" ; break ; case JSON_ERROR_UTF8 : echo "Misformed UTF-8 characters" ; break ; default : echo "Unknown Error" ; break ; } ?>
Run the instance
json_last_error ( )
none.