Home > Backend Development > PHP Tutorial > PHP uses json_decode to return NULL_PHP tutorial

PHP uses json_decode to return NULL_PHP tutorial

WBOY
Release: 2016-07-14 10:07:19
Original
1120 people have browsed it

PHP5.2 and later comes with the json_decode function, but the format requirements for json text strings are very strict.

It is very likely that the return value obtained by using this function is NULL
The return value obtained by using the json_last_error() function is JSON_ERROR_SYNTAX (Syntax error).
You can troubleshoot in the following ways.
1. The json string must be enclosed in double quotes
$output = str_replace("'", '"', $output);
2. The json string must be utf8 encoded
$output = iconv('gbk', 'utf8', $output);
3. There can be no extra commas, such as: [1,2,]
Replace with regular expression, preg_replace('/,s*([]}])/m', '$1', $output)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477869.htmlTechArticlephp5.2 comes with the json_decode function, but the format requirements for the json text string are very strict. It is very likely that the return value obtained by using this function is NULL. The return value obtained by using the json_last_error() function...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template