Home > Article > Backend Development > The json data returned by Taobao API cannot be used with json_decode_PHP tutorial
This article will introduce to you some solutions to the problem that json data returned by Taobao API cannot be used with json_decode. You can refer to it.
As the title states, this problem has been bothering me for a long time. . . After many attempts on my own and searching on the Internet, I have roughly guessed that it is a character problem. Friends on the forum said that PHP's json_decode has very strict requirements for json data, and it must be {"key":"value"}. It only works if surrounded by double quotes, and it is not compatible with some special symbols. . . For example, the BOM header of UTF-8, or the end character of C++ characters, etc. . .
After investigation, I found out. . . The reason why the json data returned by Taobao API (especially taobao.taobaoke.items.detail.get) is null after json_decode is that the returned data contains carriage returns. . . This may be caused by irregular product descriptions when some store owners renovate or fill in store descriptions. . . So use
The code is as follows
|
Copy code
|
||||
$json = str_replace(array("rn","n","r","t",chr(9),n),",$json ); $json = json_decode($json,true); |
http: //www.bkjia.com/PHPjc/632088.html