用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, 类似”\u***”的格式,如果想汉字不进行转码,这里提供三种方法

.升级PHP,在PHP5., 这个问题终于得以解决, Json新增了一个选项: JSON_UNESCAPED_UNICODE, 故名思议, 就是说, Json不要编码Unicode.
<?php
echo json_encode("中文", JSON_UNESCAPED_UNICODE);
//"中文"
.把汉字先urlencode然后再使用json_encode,json_encode之后再次使用urldecode来解码,这样编码出来的json数组中的汉字就不会出现unicode编码了。
$array = array(
'test'=>urlencode("我是测试")
);
$array = json_encode($array);
echo urldecode($array);
//{"test":"我是测试"}
.对unicode码再进行解码,解码函数如下:
function decodeUnicode($str)
{
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
create_function(
'$matches',
'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'
),
$str);
}
http://www.cnblogs.com/sink_cup/archive/2011/05/28/php_json_encode_unicode_decode.html
http://www.veryhuo.com/a/view/35112.html
http://www.alixixi.com/program/a/2011112776664.shtml

解决json_encode中文UNICODE转码问题的更多相关文章

  1. php 解决json_encode中文UNICODE转码问题

    用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, 类似"\u***"的格式,如果想汉字不进行转码,这里提供三种方法 1.升级PHP,在PHP5. ...

  2. [转]php 解决json_encode中文UNICODE转码问题

    FROM : http://blog.csdn.net/bjash/article/details/9834497 用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, ...

  3. PHP json_encode中文unicode转码问题

    用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, 类似”\u***”的格式,如果想汉字不进行转码,这里提供三种方法 1.升级PHP,在PHP5.4, 这个问题终于得 ...

  4. PHP5.4以下的json_encode中文被转码的问题

    PHP的json_encode中文被转码的问题   在php5.2中做json_encode的时候.中文会被unicode编码, php5.3加入了options参数, 5.4以后才加入JSON_UN ...

  5. IDEA Properties中文unicode转码问题

    在IDEA中创建了properties文件,发现默认中文不会自动进行unicode转码.如下 在project settings - File Encoding,在标红的选项上打上勾,确定即可 效果图 ...

  6. json_encode中文unicode的问题

    近期做微信卡券开发遇到一个问题,创建卡券post数据给服务器时返回data format error, do NOT use json unicode encode (/uxxxx/uxxxx), p ...

  7. php 解决json_encode中文问题

    众所周知使用json_encode可以方便快捷地将对象进行json编码,但是如果对象的属性中存在着中文,问题也就随之而来了.json_encode会将中文转换为unicode编码例如:'胥'经过jso ...

  8. php json_encode中文unicode问题

    php调用json_encode将中文字符串存入mysql后读取出来有问题,发现存进去的时候把'\'给去掉了.解决方法是调用json_encode时候后面加JSON_UNESCAPED_UNICODE ...

  9. PHP的json_encode中文被转码的问题

    在php5.2中做json_encode的时候.中文会被unicode编码, php5.3加入了options参数, 5.4以后才加入JSON_UNESCAPED_UNICODE,这个参数,不需要做e ...

随机推荐

  1. URAL 1001 Reverse Root(水题?)

    The problem is so easy, that the authors were lazy to write a statement for it! Input The input stre ...

  2. springmvcの神总结のreadme

    ********李守宏springmvc******** 3.== --\springmvc一个controller实现多个方法 ----\继承MultiActionController ----\配 ...

  3. 夺命雷公狗—angularjs—25—angular内置的方法(高级)

    查看版本信息 angular.version console.log(angular.version); 判断是否相等 angular.equals() var str1 = ''; var str2 ...

  4. 夺命雷公狗jquery---4内容选择器

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. C语言初学者代码中的常见错误与瑕疵(13)

    https://www.cpfn.org/bbs/viewtopic.php?f=85&t=5940&sid=ccbcf716d21191452e7c08a97b502337& ...

  6. Office 2007在安装过程中出错-解决办法

    1, 可能是因为c:\program files\common files\microsoft Shared\web server Extensions\40\bin目录下缺少Fp4autl.dll, ...

  7. kvm虚拟机virt-manager启动报错

    安装kvm,用virt-manager启动时报错如下: Traceback (most recent call last):  File "/usr/share/virt-manager/v ...

  8. linux的mtd架构分析【转】

    转自:http://blog.csdn.net/column/details/xgbing-linux-mtd.html linux mtd 嵌入式系统的存储有很多不可靠之处.随着使用容量的增大,现在 ...

  9. 内存泄露:*.hprof

    使用Memory Analyzer tool(MAT)分析内存泄漏 转账地址:http://www.blogjava.net/rosen/archive/2010/06/13/323522.html ...

  10. HDU 4315:Climbing the Hill(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...