json_encode()函数为什么不能解析带中文的JSON字符串呢?
Jun 23, 2016 pm 02:11 PM 这样就有值:
$a = '{ "a":"www", "b":2}';$arr = json_decode($a, true);
这样就返回NULL:
$a = '{ "a":"你好", "b":2}';$arr = json_decode($a, true);
为什么出现这种情况呢?该怎么解析带中文的JSON字符串呢?
回复讨论(解决方案)
json中的中文都被转码了:
$p = array("name"=>"成龙",array("age"=>55,"cur"=>"电影"));$p_json = json_encode($p);echo $p_json."<br>";#{"name":"\u6210\u9f99","0":{"age":55,"cur":"\u7535\u5f71"}}#\u6210\u9f99 => 成龙,#\u7535\u5f71 => 电影print_r(json_decode($p_json));#stdClass Object ( [name] => 成龙 [0] => stdClass Object ( [age] => 55 [cur] => 电影 ) )
json中的中文都被转码了:
PHP code
$p = array("name"=>"成龙",array("age"=>55,"cur"=>"电影"));
$p_json = json_encode($p);
echo $p_json."
";
#{"name":"\u6210\u9f99","0":{"age":55,"cur":"\u7535\u5f71"}}
#\u6210\……
那它也应该能出来东西啊,不能是NULL吧
在你的编辑器中把字符集改为utf-8
文件编码 utf-8 或者 iconv 自己再转
在你的编辑器中把字符集改为utf-8
嗯好了,谢谢啊!
不能解析中文,我设置了utf-8
header("Content-Type: text/html; charset=utf-8");$p = array("name"=>"成龙",array("age"=>55,"cur"=>"电影"));$p_json = json_encode($p);

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey
