How does php convert unicode encoding in json into Chinese characters?

Source: Internet
Author: User
How does php convert unicode encoding in json into Chinese characters? There are two json data
$ D = [{"_ id": {"$ id": "4fda7d42741d727c14000000"}, "name": "\ u519c \ u592b \ u5c71 \ u6cc9", "bc ": "123456", "pic": "d: pic \ water.jpg", "aid": "232fd4df3"}]
$ C = [{"_ id": {"$ id": "4fdaa7f3741d725816000000"}, "bc": "012345678", "name ": "\ u7ef4 \ u8fbe \ u7eb8 \ u5dfe", "cls": {"id": "125", "name": "\ u65e5 \ u7528 \ u54c1 "}, "std": {"name": "\ u5f20 \ u6570", "val": "10"}]

How to convert unicode characters into Chinese characters

$ D = [{"_ id": {"$ id": "4fda7d42741d727c14000000"}, "name": "Nongfu Spring", "bc": "123456 ", "pic": "d: pic \ water.jpg", "aid": "232fd4df3"}]
$ C = [{"_ id": {"$ id": "4fdaa7f3741d725816000000"}, "bc": "012345678", "name": "Vida paper towel ", "cls": {"id": "125", "name": "Daily Necessities"}, "std": {"name": "Zhangshu", "val ": "10"}]

Which of the following can help you solve the problem? thank you ~~


Reply to discussion (solution)

Linux
$ Str = preg_replace ("# \\\ u ([0-9a-f] {4}) # ie", "iconv ('ucs-2be ', 'utf-8 ', pack ('h4 ',' \ 1 ') ", $ str );

Windows
$ Str = preg_replace ("# \\\ u ([0-9a-f] {4}) # ie", "iconv ('ucs-2le', 'utf-8 ', pack ('h4 ','......

Reference the reply on the third floor:

Linux
$ Str = preg_replace ("# \\\ u ([0-9a-f] {4}) # ie", "iconv ('ucs-2be ', 'utf-8 ', pack ('h4 ',' \ 1 ') ", $ str );

Windows
$ Str = preg_replace ("# \\\ u ([0-9a-f] {4}) # ie", "iconv ('ucs-2le', 'utf-8 '......

No, is it written like this?
$ C = preg_replace ("# \\\ u ([0-9a-f] {4}) # ie", "iconv ('ucs-2le', 'utf-8 ', pack ('h4 ',' \ 1 ') ", $ c );
Echo $ c;
$ C output is
[{"_ Id": {"$ id": "4fdaa7f3741d725816000000"}, "bc": "012345678", "name ":"? Tired? Too many? "," Cls ": {" id ":" 125 "," name ":"? Activities> 〉?? "}," Std ": {" name ":"??? "," Val ":" 10 "}]
I am a windows platform. how can I solve this problem?

How can this problem be solved?

I tried,

$ Str = '$ d = [{"_ id": {"$ id": "4fda7d42741d727c14000000"}, "name": "\ u519c \ u592b \ u5c71 \ u6cc9 ", "bc": "123456", "pic": "d: pic \ water.jpg", "aid": "232fd4df3"}]
$ C = [{"_ id": {"$ id": "4fdaa7f3741d725816000000"}, "bc": "012345678", "name ": "\ u7ef4 \ u8fbe \ u7eb8 \ u5dfe", "cls": {"id": "125", "name": "\ u65e5 \ u7528 \ u54c1 "}, "std": {"name": "\ u5f20 \ u6570", "val": "10"}] ';

$ Str = preg_replace ("# \\\ u ([0-9a-f] {4}) # ie", "iconv ('ucs-2be ', 'utf-8 ', pack ('h4 ',' \ 1 ') ", $ str );
Echo $ str;



If the code is garbled, remember to change the browser encoding.

Remember to use UTF-8 after encoding

I know what you mean ~ No problem as long as UTF-8 is transmitted

How can this problem be solved?

I tried,

$ Str = '$ d = [{"_ id": {"$ id": "4fda7d42741d727c14000000"}, "name": "\ u519c \ u592b \ u5c71 \ u6cc9 ", "bc": "123456", "pic": "d: pic \ water.jpg", "aid": "232fd4df3"}]
$ C = [{"_ id": {"$ id": "4fdaa7f3741d7 ......
Why can't I display it? the result is as follows:
$ D = [{"_ id": {"$ id": "4fda7d42741d727c14000000"}, "name ":"?? How does one distinguish between two variables? "," Bc ":" 123456 "," pic ":" d: pic \ water.jpg "," aid ": "232fd4df3"}] $ c = [{"_ id": {"$ id": "4fdaa7f3741d725816000000"}, "bc": "012345678", "name ": "Discuss your contribution", "cls": {"id": "125", "name ":"? WHY ??? "}," Std ": {" name ":" identifier ?? "," Val ":" 10 "}]
I can't use ie. why? Solution ~~

How can this problem be solved?

I tried,

$ Str = '$ d = [{"_ id": {"$ id": "4fda7d42741d727c14000000"}, "name": "\ u519c \ u592b \ u5c71 \ u6cc9 ", "bc": "123456", "pic": "d: pic \ water.jpg", "aid": "232fd4df3"}]
$ C = [{"_ id": {"$ id": "4fdaa7f3741d7 ......
Oh ~~ Yes, yes. Add header ("Content-type: text/html; charset = utf-8,
Thank you for your help.

Lian is easy to handle

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.