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.