Json_decode cannot be used for json data returned by Taobao API

Source: Internet
Author: User

For example, this problem has been bothering me for a long time... After many attempts and searching on the Internet, I have probably guessed that it is a character issue. My friends on the forum said that PHP's json_decode has strict requirements on json data, it must be surrounded by double quotation marks of {"key": "value"}. Besides, it is incompatible with some special symbols... For example, the BOM header of the UTF-8, or the ending character of the C ++ character, etc...

After troubleshooting, I found that... Json data returned by taobao API (especially taobao. Taobake. items. detail. get). The result of json_decode is null because the returned data contains a carriage return... This may be the result of some shopkeepers entering shop descriptions during decoration or nonstandard product descriptions... Therefore

The code is as follows: Copy code

$ Json = str_replace (array ("rn", "n", "r", "t", chr (9), \ n), ", $ json );
$ Json = json_decode ($ json, true );

This will solve this problem.

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.