json_last_error_msg() – Trả về chuỗi lỗi của lệnh gọi json_encode () hoặc json_decode () cuối cùng.
json_last_error_msg ( void ) : string
– Trả về chuỗi lỗi của lệnh gọi json_encode () hoặc json_decode () cuối cùng, không chỉ định JSON_THlaw_ON_ERROR.
<?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';
}
}
?>Các bạn có thể xem chi tiết hơn trên php.net.
Hi vọng với bài viết này, bạn đã hiểu rõ ứng dụng của hàm json_last_error_msg() trong PHP. Nếu bạn thấy bài viết hay và có ý nghĩa hãy like và chia sẻ bài viết này để mọi người cùng nhau học tập nhé.
Cảm ơn các bạn đã ghé thăm codetutam.com
Bình luận: