Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: json_last_error_msg - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: json_last_error_msg

2025-04-27

json_last_error_msg

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

json_last_error_msg返回最后一次调用 json_encode() 或 json_decode() 时产生的错误信息

说明

json_last_error_msg(): string

当没有设置 JSON_THROW_ON_ERROR 参数时,返回最后一次调用 json_encode()json_decode() 产生的错误信息。

参数

此函数没有参数。

返回值

成功则返回错误信息,如果没有错误产生则返回 "No error"

参见

添加备注

用户贡献的备注 1 note

up
19
Anonymous
9 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';
}
}
?>

官方地址:https://www.php.net/manual/en/function.json-last-error-msg.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3