Home  >  Article  >  Backend Development  >  The json data returned by Taobao API cannot be used with json_decode_PHP tutorial

The json data returned by Taobao API cannot be used with json_decode_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:57:281193browse

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

$json = str_replace(array("rn","n","r","t",chr(9),n),",$json ); $json = json_decode($json,true);
The code is as follows
 代码如下 复制代码

$json = str_replace(array(“rn”,”n”,”r”,”t”,chr(9),n),”,$json );      
$json = json_decode($json,true);    

Copy code

This will solve the problem. http://www.bkjia.com/PHPjc/632088.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/632088.html
TechArticle
This article will introduce to you some solutions to the problem that the json data returned by Taobao API cannot be used with json_decode. Introduction, everyone can refer to it. As the title says, this problem has been bothering me for a long time...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn