京东是中国的综合网络零售商,是中国电子商务领域受消费者欢迎和具有影响力的电子商务网站之一,在线销售家电、数码通讯、电脑、家居百货、服装服饰、母婴、图书、食品、在线旅游等12大类数万个品牌百万种优质商品。京东在2012年的中国自营B2C市场占据49%的份额,凭借全供应链继续扩大在中国电子商务市场的优势。
商品分类的作用
分类:是用户从自己体验的角度对事物、信息进行判断和归类,目的是让现实世界显得更加有序。
定位:是从商家或者产品的角度对商品、服务进行的场景化定义,是为了将自己的商品、服务与其他事物区别开来,而且是需要推入到用户的判断标准中,这样才能建立自己的品牌。
cat_get-获得jd商品分类 公共参数
名称 类型 必须 描述 key String 是 调用key(必须以GET方式拼接在URL中) secret String 是 调用密钥 api_name String 是 API接口名称(包括在请求地址中)[item_search,item_get,item_search_shop等] cache String 否 [yes,no]默认yes,将调用缓存的数据,速度比较快 result_type String 否 [json,jsonu,xml,serialize,var_export]返回数据格式,默认为json,jsonu输出的内容中文可以直接阅读 lang String 否 [cn,en,ru]翻译语言,默认cn简体中文 version String 否 API版本
请求参数:cid=0
参数说明:cid:商品分类ID,可以用cid=0来获得所有一级类目
响应参数
名称 类型 是否隐私 示例值 描述 id Int 54 商品分类ID name String 服饰配件、饰品 分类名 pid String 0 父分类ID root_id String 0 根分类ID item Mix {"id": 127464010,"name": "帽子/头巾","pid": "54","root_id": 0,sub[]} 子分类id:子分类名称 Java代码请求示例
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.nio.charset.Charset; import org.json.JSONException; import org.json.JSONObject; import java.io.PrintWriter; import java.net.URLConnection;
public class Example { private static String readAll(Reader rd) throws IOException { StringBuilder sb = new StringBuilder(); int cp; while ((cp = rd.read()) != -1) { sb.append((char) cp); } return sb.toString(); } public static JSONObject postRequestFromUrl(String url, String body) throws IOException, JSONException { URL realUrl = new URL(url); URLConnection conn = realUrl.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(body); out.flush(); InputStream instream = conn.getInputStream(); try { BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8"))); String jsonText = readAll(rd); JSONObject json = new JSONObject(jsonText); return json; } finally { instream.close(); } } public static JSONObject getRequestFromUrl(String url) throws IOException, JSONException { URL realUrl = new URL(url); URLConnection conn = realUrl.openConnection(); InputStream instream = conn.getInputStream(); try { BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8"))); String jsonText = readAll(rd); JSONObject json = new JSONObject(jsonText); return json; } finally { instream.close(); } } public static void main(String[] args) throws IOException, JSONException { // 请求示例 url 默认请求参数已经URL编码处理 String url = "/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&cid=0"; JSONObject json = getRequestFromUrl(url); System.out.println(json.toString()); }
} 错误码解释
状态代码(error_code) 状态信息 详细描述 是否收费 0000 success 接口调用成功并返回相关数据 是 2000 Search success but no result 接口访问成功,但是搜索没有结果 是 4000 Server internal error 服务器内部错误 否 4001 Network error 网络错误 否 4002 Target server error 目标服务器错误 否 4003 Param error 用户输入参数错误 否 4004 Account not found 用户帐号不存在 否 4005 Invalid authentication credentials 授权失败 否 4006 API stopped 您的当前API已停用 否 4007 Account stopped 您的账户已停用 否 4008 API rate limit exceeded 并发已达上限 否 4009 API maintenance API维护中 否 4010 API not found with these values API不存在 否 4012 Please add api first 请先添加api 否 4013 Number of calls exceeded 调用次数超限 否 4014 Missing url param 参数缺失 否 4015 Wrong pageToken 参数pageToken有误 否 4016 Insufficient balance 余额不足 否 4017 timeout error 请求超时 否 5000 unknown error 未知错误 否 文章内容有限,欢迎私信沟通!