PHP json_decode cannot parse special question mark characters. json_decode question mark

Source: Internet
Author: User

PHP json_decode cannot parse special question mark characters. json_decode question mark

 

When requesting information through other interfaces, some characters may occasionally occur. if the following conditions are met, json_decode will return null.

However, this situation is not generally caused by the overall encoding problem, because it is parsed using UTF-8 encoding.

 

 

In this case, both Chinese and English are used, but some blank characters cannot be recognized.

 

The observation of the system logic should be due to the fact that non-UTF-8 characters can be recognized when the characters are saved in the previous section, which is not affected in json_encode, this directly causes invalid characters when the interface obtains data.

 

Solution:

 

$ Return_data = mb_convert_encoding ($ return_data, "UTF-8", "UTF-8 ");

The characters returned through the curl request are forcibly encoded at one time. In this case, the original UTF-8 encoded text will not be affected, and UTF-8 unidentifiable characters will be forcibly parsed, after the characters are parsed, they will become English characters? ,

In this way, json_decode can be smoothly implemented.

 

Related Article

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.