Home  >  Article  >  Backend Development  >  PHP json_encode 中文乱码,该怎么解决

PHP json_encode 中文乱码,该怎么解决

WBOY
WBOYOriginal
2016-06-13 11:53:151120browse

PHP json_encode 中文乱码
如标题,  这个问题不用urlencode()的方式该怎样解决?      
              希望各位指教指教。
------解决方案--------------------
首先那不是乱码,而是 unicode 的符号表示
如果希望仍保留中文字样,那么递归应用 urlencode 是最佳选择,同时还使数据不限与 utf-8 编码

当然你也可以对 json_encode 的结果做一下编码逆转换,但涉及正则,效率要低些
------解决方案--------------------
如果你使用的是 php5.4 及以上,就简单了
只需给 json_encode 加上第二个参数: JSON_UNESCAPED_UNICODE

Statement:
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