Maison  >  Article  >  développement back-end  >  json_encode()函数为何不能解析带中文的JSON字符串呢

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

WBOY
WBOYoriginal
2016-06-13 13:26:54979parcourir

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);



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

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

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



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

------解决方案--------------------
在你的编辑器中把字符集改为utf-8
------解决方案--------------------
文件编码 utf-8 或者 iconv 自己再转
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn