Home > Backend Development > PHP Tutorial > json_decode()问题

json_decode()问题

WBOY
Release: 2016-06-23 13:09:32
Original
1225 people have browsed it

        $vvv='{"subscribe":1,"openid":"ol2E7uLeDEi4VCBwrXI0KRwcvnyo","nickname":"xhm","sex":2,"language":"zh_CN","city":"mñW3","province":"^N","country":"","headimgurl":"http:\/\/wx.qlogo.cn\/mmopen\/PiajxSqBRaELiaLZZTltPhZobM3QcvGyGgRXnAlcPm8iaoWQWvuNuIFZk3kOOeNCQok1W4l6zashSAMfMSiasN4eZhbuib4NXuQNmQuFMn2XBd9M\/0","subscribe_time":1458906765,"remark":"","groupid":0}';        var_dump(json_decode($vvv,true));exit;
Copy after login

转不了,返回值为null,是因为city和province的值 是特殊符号,请问怎样处理?


回复讨论(解决方案)

特殊符号进行转意

应该先解决city和province乱码的问题,再去json_decode,因为手册上说,json_decode必须是utf-8的编码格式。可以尝试用iconv相关函数试试

应该先解决city和province乱码的问题,再去json_decode,因为手册上说,json_decode必须是utf-8的编码格式。可以尝试用iconv相关函数试试

iconv试了,不行

city = 深圳
province = 广东

$vvv = iconv('ucs-2', 'utf-8', $vvv);var_dump(json_decode($vvv,true));
Copy after login
Copy after login
需要注意的是,你的 $vvv 必须是原始渠道的来的数据,而不是你贴出的经复制粘贴的数据
原始的 unicode 数据,经过复制粘贴,就无法再恢复了

"city":"mñW3","province":"^N
有不是utf8的数据,需要先处理

city = 深圳
province = 广东

$vvv = iconv('ucs-2', 'utf-8', $vvv);var_dump(json_decode($vvv,true));
Copy after login
Copy after login
需要注意的是,你的 $vvv 必须是原始渠道的来的数据,而不是你贴出的经复制粘贴的数据
原始的 unicode 数据,经过复制粘贴,就无法再恢复了


不行啊,我这数据是从微信接口那里得来的,我没有处理过就json_decode了,但是微信那里有些资料的确是有乱码的

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