Why is the result of converting json_decode to a uft-8 string null?

Source: Internet
Author: User
Why is the result of converting json_decode to a uft-8 string null?
 
 
 0) {// $ str = mb_convert_encoding ($ str, "GBK", "UTF-8"); $ jo = json_decode ($ str); // Chinese, the transfer is nullprint_r ("\ n ++ \ n ". $ jo. "\ n ===\ n"); $ msg_id = $ jo-> msg_id; // An error is returned here .} Echo '';?>


Reply to discussion (solution)

Json format is incorrect. you can echo the json string to be converted by j to see if it complies with the standard json format.

A little simpler:

 
 
 
"; Print" $ str = ". $ str. "\ n"; if (strlen ($ str)> 0) {$ jo = json_decode ($ str); // Chinese, the transfer is nullprint_r ("\ n ++ \ n ". $ jo. "\ n ===\ n"); $ msg_id = $ jo-> txt ;}

I saved the t1.php file as UTF-8 encoded.

But still not.

Add the following
It is no longer in json format.

Print_r ("\ n ++ \ n". $ jo. "\ n ===\ n ");
What is it here?

Echo $ _ POST ["text"];
Look at what it is. most of the quotes are escaped.

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.