首页 > 大数据 > 数据分析 > 京东商品详情API返回值应用实践
京东商品详情API(如
jd.item.get或
jd.union.open.goods.query)是京东开放平台提供的核心接口,用于通过
商品ID(skuId)或
店铺ID检索指定商品的详细信息。该接口支持获取商品基础信息、价格、库存、规格参数、用户评价等多维度数据,是电商数据分析、竞品监控、个性化推荐等场景的重要工具。
API返回的JSON数据包含以下核心字段,结构示例如下:
json{"code": "0000","message": "成功","data": {"item": {"skuId": "123456789","title": "Redmi K60 Pro 5G手机 12GB+256GB 墨羽","price": 2999.00,"original_price": 3299.00,"promotion": {"type": "满减","desc": "满3000减300","valid_time": "2025-07-25至2025-07-31"},"images": ["https://img.jd.com/detail1.jpg","https://img.jd.com/detail2.jpg"],"desc": "搭载骁龙8 Gen2处理器,支持120W快充...","stock": 50,"skuList": [{"skuId": "123456","name": "墨羽 12GB+256GB","price": 2999.00,"stock": 50}],"attributes": [{"name": "颜色", "value": "墨羽"},{"name": "内存", "value": "12GB+256GB"}],"category": {"id": "123","name": "5G手机"},"brand": {"id": "1001","name": "Redmi","logo": "https://img.jd.com/brand/logo.jpg"},"afterSaleService": {"return_policy": "7天无理由退货","warranty": "1年质保"},"reviews": {"count": 1000,"rating": 4.8,"positive_rate": "95%"}}}}
skuId:商品唯一标识符,用于定位具体商品或SKU(如不同颜色、尺寸的变体)。title:商品标题,包含品牌、型号、核心功能的描述性文本。images:商品图片URL列表,包括主图和详情图,支持高清展示。desc:商品详细描述,可能包含HTML标签或纯文本,介绍材质、功能、使用方法等。price:当前售价(元)。original_price:原价,用于划线价展示。promotion:促销活动详情,包括类型(如满减)、描述(如“满3000减300”)及有效期。stock:实时库存数量,支持判断商品可售性(如“inStock”表示有货)。skuList:不同规格(如颜色、内存)的价格及库存信息,每个SKU包含
skuId、
name、
price、
stock等字段。attributes:商品属性列表,包含颜色、尺寸、重量、产地等结构化数据。category:商品所属类目路径,如“手机>5G手机>Redmi”。brand:品牌信息,包括品牌ID、名称及Logo链接。reviews:评价数据,包含评价数量(
count)、评分(
rating,如4.8分)及好评率(
positive_rate)。afterSaleService:售后服务条款,包括退换货政策(如“7天无理由退货”)及保修期限(如“1年质保”)。https://api.jd.com/routerjson。method:接口方法名,如
jd.union.open.goods.query。app_key:应用密钥,需在京东开放平台创建应用后获取。timestamp:请求时间戳,格式为
YYYY-MM-DD HH:mm:ss。v:接口版本号,如
1.0。param_json:JSON格式的查询条件,如
{"skuIds": ["123456789"]}。pythonimport hashlibdef generate_sign(params, app_secret):sorted_params = sorted(params.items())sign_str = app_secret + ''.join(f"{k}{v}" for k, v in sorted_params) + app_secretreturn hashlib.md5(sign_str.encode()).hexdigest().upper()price和
promotion数据。stock字段实时监控库存。attributes中的规格信息(如颜色、内存)。promotion中的满减规则,生成“满3000减300”等文案。reviews中的评分及好评率生成评价分析报告。monthly_sales(需申请权限)分析销量趋势。pythonimport requestsimport hashlibimport timeAPP_KEY = 'your_app_key'APP_SECRET = 'your_app_secret'API_URL = 'https://api.jd.com/routerjson'def generate_sign(params):sorted_params = sorted(params.items())sign_str = APP_SECRET + ''.join(f"{k}{v}" for k, v in sorted_params) + APP_SECRETreturn hashlib.md5(sign_str.encode()).hexdigest().upper()params = {'method': 'jd.union.open.goods.query','app_key': APP_KEY,'timestamp': time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),'v': '1.0','param_json': '{"skuIds": ["123456789"]}'}params['sign'] = generate_sign(params)response = requests.post(API_URL, data=params)data = response.json()if data['code'] == '0000':print("商品标题:", data['data']['item']['title'])print("当前价格:", data['data']['item']['price'], "元")print("库存数量:", data['data']['item']['stock'], "件")else:print("请求失败:", data['message'])
通过以上实践,开发者可高效利用京东商品详情API实现数据驱动的电商运营策略。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70046834/viewspace-3094590/ ,如需转载,请注明出处,否则将追究法律责任。