3', PHPWEB:'php.cn', settings:'settings', FullScreen:'Full Screen', Speed:'Speed', BrainwashingLoop:'Loop', speedNormal:'Normal', click_to_see:'Click to see full code for direct edit', nextSection:'Next Section', Cancel:'Cancel', Confirm:'Confirm', all_lang_string:'zh|en|zh-tw|ja|ko|ms|fr|de', Next:'Next', Previous:'Previous', };
Home > Backend Development > PHP Tutorial > json_encode()函数为何不能解析带中文的JSON字符串呢

json_encode()函数为何不能解析带中文的JSON字符串呢

WBOY
Release: 2016-06-13 13:26:54
Original
1026 people have browsed it

json_encode()函数为什么不能解析带中文的JSON字符串呢?
这样就有值:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$a = '{ "a":"www", "b":2}';
$arr = json_decode($a, true);

Copy after login


这样就返回NULL:
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$a = '{ "a":"你好", "b":2}';
$arr = json_decode($a, true);

Copy after login


为什么出现这种情况呢?该怎么解析带中文的JSON字符串呢?

------解决方案--------------------
在你的编辑器中把字符集改为utf-8
------解决方案--------------------
文件编码 utf-8 或者 iconv 自己再转
Related labels:
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