阿里巴巴开放平台上获取产品分类和属性

       阿里巴巴开放平台有详细的API以及api tools在线测试工具,获取一些公开的数据非常方便。

       目前公司新的平台需要产品分类和产品公共属性,本来是打算让测试人员去整理的,后来发现工作量太大了,就想直接通过阿里巴巴平台上面把分类和属性数据导出来整理,开发人员花费了2天时间,导出了大概近1w条产品分类和18w条产品属性数据。

       产品分类是josn格式,json的数据结构如下

      

{
    "result": {
        "total": 56,
        "toReturn": [
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 122916001,
                "catsName": "宠物及园艺",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 1,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 122916002,
                "catsName": "汽车用品",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 2,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 58,
                "catsName": "照明工业",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 3,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 10166,
                "catsName": "女装",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 4,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 10165,
                "catsName": "男装",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 5,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 57,
                "catsName": "电子元器件",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 6,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 53,
                "catsName": "传媒、广电",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 7,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 70,
                "catsName": "安全、防护",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 8,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 68,
                "catsName": "包装",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 9,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 52,
                "catsName": "纸业",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 10,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 67,
                "catsName": "办公、文教",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 11,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 7,
                "catsName": "数码、电脑",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 12,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 5,
                "catsName": "电工电气",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 13,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 80,
                "catsName": "眼镜及配件",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 14,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 4,
                "catsName": "纺织、皮革",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 15,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 312,
                "catsName": "内衣",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": false,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 16,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 311,
                "catsName": "童装",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 17,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 54,
                "catsName": "服饰配件、饰品",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": false,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 18,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 1038378,
                "catsName": "鞋",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 19,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 1042954,
                "catsName": "箱包皮具",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 20,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            },
            {
                "supportMixWholesale": false,
                "tradeType": 1,
                "applySpu": false,
                "catsId": 3007,
                "catsName": "个人防护",
                "supportSKUPrice": false,
                "supportOnlineTrade": false,
                "batchPost": true,
                "childrenCats": [],
                "spuPriceExt": false,
                "leaf": false,
                "parentCats": [
                    {
                        "order": 56,
                        "parentCatsId": 0
                    }
                ],
                "applyRealPrice": false,
                "catsDescription": ""
            }
        ],
        "success": true
    }
}

 

       对应获取该json的代码:

   

     

 public static String loadJson(String categoryId) {
        StringBuilder json = new StringBuilder();
        try {
            URL urlObject = new URL("https://gw.open.1688.com/openapi/param2/1/cn.alibaba.open/offerPostFeatures.get/1002774?categoryID="+categoryId);
            URLConnection uc = urlObject.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "utf-8"));
            String inputLine = null;
            while ((inputLine = in.readLine()) != null) {
                json.append(inputLine);
            }
            in.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return json.toString();
    }

 

     json的解析代码:

 

 

   public static List jsonPar(String jsonStr)
            throws JSONException, SQLException {

        List listSurveyVO = new ArrayList();
        JSONObject jsonObject  = new JSONObject(jsonStr);
        jsonObject = jsonObject.getJSONObject("result");
        JSONArray results = jsonObject.getJSONArray("toReturn");
 
        for (int i = 0; i < results.length(); i++) {
                SurveyVO surveyVO = new SurveyVO();
                List listparentCategoryID = new ArrayList();
                JSONObject result = results.getJSONObject(i);
                surveyVO.setCatsId(result.getString("catsId"));
                surveyVO.setCatsName(result.getString("catsName"));
                for (int count = 0; count < result.getJSONArray("parentCats").length(); count++) {
                    listparentCategoryID.add(result.getJSONArray("parentCats").getJSONObject(count)
                            .getString("parentCatsId"));

                }
                surveyVO.setListparentCategoryID(listparentCategoryID);
                listSurveyVO.add(surveyVO);
                
         }
 
        return listSurveyVO;

    }

 

        上述是对产品分类的操作,对产品属性只要遍历末级分类即可。

你可能感兴趣的:(阿里巴巴API)