Home > Backend Development > PHP Tutorial > php的json_encode疑问

php的json_encode疑问

WBOY
Release: 2016-06-20 12:34:05
Original
929 people have browsed it

php的json_encode会把数组里面的汉字转成类似\u821c这种字符串,有没有什么办法不转呢?或者反解一下但仍然保持json格式。


回复讨论(解决方案)

 你用js读出来的时候就是汉字

我知道js读出来是汉字,但是我需要的答案不是你说的这个,而是我问的,而且我也没说我是用js读取呀。。。

php 5.4 及以后,可加上第二个参数 JSON_UNESCAPED_UNICODE 

或干脆

$a = array('charset' => '中文');array_walk_recursive($a, function(&$v) { $v = urlencode($v); });echo urldecode(json_encode($a));
Copy after login
Copy after login
{"charset":"中文"}

连是否时 utf-8 也不要管了

参考: http://blog.csdn.net/fdipzone/article/details/28766357

php 5.4 及以后,可加上第二个参数 JSON_UNESCAPED_UNICODE

或干脆

$a = array('charset' => '中文');array_walk_recursive($a, function(&$v) { $v = urlencode($v); });echo urldecode(json_encode($a));
Copy after login
Copy after login
{"charset":"中文"}

连是否时 utf-8 也不要管了



我的php5.4 chm手册上面居然没写有第二个参数,看样子要更新手册了。。。

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