Question about json_encode in php

Source: Internet
Author: User
Php's json_encode question: php's json_encode will convert the Chinese characters in the array into strings similar to \ u821c. Is there any way not to convert them? Or reverse, but still in json format.


Reply to discussion (solution)

You use js to read Chinese characters.

I know that js reads Chinese characters, but the answer I need is not what you said, but what I asked, and I didn't say that I used js to read it...

Php 5.4 and later, the second parameter JSON_UNESCAPED_UNICODE can be added

Or simply

$ A = array ('charset' => 'China'); array_walk_recursive ($ a, function (& $ v) {$ v = urlencode ($ v );}); echo urldecode (json_encode ($ ));
{"Charset": "Chinese "}

Do not worry about UTF-8 connection.

Reference: http://blog.csdn.net/fdipzone/article/details/28766357

Php 5.4 and later, the second parameter JSON_UNESCAPED_UNICODE can be added

Or simply

$ A = array ('charset' => 'China'); array_walk_recursive ($ a, function (& $ v) {$ v = urlencode ($ v );}); echo urldecode (json_encode ($ ));
{"Charset": "Chinese "}

Do not worry about UTF-8 connection.



I didn't write the second parameter in the php5.4 chm Manual. it looks like I have to update the manual...

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.