淘宝API返回的json数据无法用json_decode的问题
本文章来给各位介绍我在使用淘宝 API 返回的json数据无法用json_decode的问题的一些解决办法介绍,大家可参考。
如题,这个问题困扰我已久。。。经过自己的多次尝试,和到网上搜索,我已大概猜测到是字符的问题,论坛上的朋友说,PHP的json_decode对json数据要求非常严格,必须是{“key”:”value”}的双引号包围才行,而且,对一些特殊符号不兼容。。。例如UTF-8的 BOM头,或者是C++字符的结束符等等。。。
经过排查,我发现。。。淘宝API返回的json数据(特别是taobao.taobaoke.items.detail.get),之所以json_decode后,结果为null,原因就是返回的数据含有回车符。。。这可能是一些店主在装修时,或者填写店铺描述,商品描述不规范所留下的。。。所以用
代码如下 | 复制代码 |
$json = str_replace(array(“rn”,”n”,”r”,”t”,chr(9),\n),”,$json ); |
这样就可以解决这个问题了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor
