(PHP 5 >= 5.5.0, PHP 7, PHP 8)
json_last_error_msg — Devuelve el mensaje del último error ocurrido durante la llamada a la función json_validate(), json_encode() o json_decode()
Devuelve el string de error del último llamado a json_validate() , json_encode() o json_decode() ,
que no haya especificado JSON_THROW_ON_ERROR .
Esta función no contiene ningún parámetro.
Devuelve el mensaje de error en caso de éxito, o
"No error" si no ha ocurrido ningún error,
o false si ocurre un error.
Here's an updated version of the function:
<?php
if (!function_exists('json_last_error_msg')) {
function json_last_error_msg() {
static $ERRORS = array(
JSON_ERROR_NONE => 'No error',
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
);
$error = json_last_error();
return isset($ERRORS[$error]) ? $ERRORS[$error] : 'Unknown error';
}
}
?>