我给你最简洁、最实用、程序员直接复制运行的版本专门校验京东 API 返回的商品数据是否准确、合法、可用。一、校验核心只做最重要的校验返回结构是否正常商品 IDsku_id是否有效商品标题是否存在价格是否合法0主图是否有效店铺 / 类目是否存在数据格式是否正确数字、字符串二、Python 校验代码直接用python运行def check_jd_item_accuracy(json_data): 京东商品详情API数据准确性校验 返回(True/False, 信息说明) try: # 1. 检查顶层结构是否正确 if jd_item_get_response not in json_data: return False, 返回格式错误无 jd_item_get_response res json_data[jd_item_get_response] item res.get(item, {}) if not item: return False, 未获取到商品信息 # 2. 商品SKU_ID 校验必须是数字 sku_id item.get(sku_id) if not sku_id or not str(sku_id).isdigit(): return False, fsku_id 无效{sku_id} # 3. 标题校验不能为空 title item.get(title) if not title or len(title) 5: return False, 商品标题无效或过短 # 4. 价格校验必须 0 price item.get(price, 0) try: price_val float(price) if price_val 0: return False, f价格异常{price} except: return False, f价格格式错误{price} # 5. 主图链接校验 img_url item.get(img_url) if not img_url or http not in img_url: return False, 商品主图无效 # 6. 店铺信息校验 shop_name item.get(shop_name) if not shop_name: return False, 店铺名称不存在 # 7. 类目ID校验 cid item.get(cid) if not cid: return False, 商品类目 cid 不存在 # 全部校验通过 return True, 京东商品数据校验通过准确有效 except Exception as e: return False, f校验异常{str(e)}三、使用示例python运行# 假设这是你调用京东API返回的JSON json_result requests.get(api_url, paramsparams).json() # 执行校验 ok, msg check_jd_item_accuracy(json_result) print(ok, msg)四、京东 API 标准返回 JSON用于测试json{ jd_item_get_response: { item: { sku_id: 100012345678, title: Apple iPhone 15 黑色 128G, price: 5999.00, img_url: https://img14.360buyimg.com/xxx.jpg, shop_name: 京东自营, cid: 9987 } } }五、这个校验能帮你避免哪些问题数据为空导致程序崩溃价格异常、负数、0 元导致业务错误商品 ID 无效图片失效导致搬家 / 铺货失败字段缺失导致数据分析出错API 异常返回不被发现六、一句话总结京东 API 商品数据校验 结构正确 字段非空 数值合法让你的数据分析、商品搬家、ERP、监控系统100% 稳定不出错。