Json_decode ()

Source: Internet
Author: User
Json_decode ()
        $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;

The return value is null because the values of city and province are special characters. how can this problem be solved?


Reply to discussion (solution)

Conversion of special symbols

The city and province garbled characters should be solved first, and then json_decode, because in the manual, json_decode must be UTF-8 encoded. Try iconv functions.

The city and province garbled characters should be solved first, and then json_decode, because in the manual, json_decode must be UTF-8 encoded. Try iconv functions.

Iconv tried. no.

City = Shenzhen
Province = Guangdong

$vvv = iconv('ucs-2', 'utf-8', $vvv);var_dump(json_decode($vvv,true));
It should be noted that your $ vvv must be the data from the original channel, rather than the copied and pasted data you posted.
The original unicode data cannot be restored after being copied and pasted.

"City": "mñw3", "province": "^ N
If there is data that is not utf8, it must be processed first.

City = Shenzhen
Province = Guangdong

$vvv = iconv('ucs-2', 'utf-8', $vvv);var_dump(json_decode($vvv,true));
It should be noted that your $ vvv must be the data from the original channel, rather than the copied and pasted data you posted.
The original unicode data cannot be restored after being copied and pasted.


No, I got this data from the interface. I have not processed json_decode, but some of the information is indeed garbled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.