PHP 8.3.4 Released!

json_last_error_msg

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

json_last_error_msgDevuelve el string con el error de la última llamada a json_encode() o a json_decode()

Descripción

json_last_error_msg(): string

Parámetros

Esta función no tiene parámetros.

Valores devueltos

Devuelve el mensaje de error en caso de éxito, "No Error" si no ocurrió ningún error, o false en caso de error.

Ver también

add a note

User Contributed Notes 1 note

up
19
Anonymous
8 years ago
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';
}
}
?>
To Top