前言:

  最近在做商家发布产品,调用京东sdk,发现问题很多,而且还是在我同事的帮助下完成的,摸索中,菜鸟还请高手门多多提携才好,入正题

首先是引用jd的sdk啦,京东sdk中发布商品需要调用一个

360buy.ware.get.attribute的接口和一个新增商品的接口

文档中提示接口调用如下(.net的)

360buy.ware.get.attribute调用示例(.net)

  1. IJdClient client = new DefaultJdClient(url, appkey, appsecret);
  2.  
  3. CategoryAttributeSearchRequest req = new CategoryAttributeSearchRequest();
  4.  
  5. req.cid = "jingdong" ; req.iskeyprop = "jingdong" ; req.issaleprop = "jingdong" ; req.aid = "jingdong" ; req.fields = "jingdong" ;
  6.  
  7. CategoryAttributeSearchResponse response = client.Execute (req, token, DateTime.Now.ToLocalTime());

360buy.ware.add调用示例(.net)

  1. IJdClient client = new DefaultJdClient(url, appkey, appsecret);
  2.  
  3. WareAddRequest req = new WareAddRequest();
  4.  
  5. req.tradeno = "jingdong" ; req.warelocation = "jingdong" ; req.cid = "jingdong" ; req.shopcategory = "jingdong" ; req.title = "jingdong" ; req.upccode = "jingdong" ; req.optiontype = "jingdong" ; req.itemnum = "jingdong" ; req.stocknum = "jingdong" ; req.producter = "jingdong" ; req.wrap = "jingdong" ; req.length = "jingdong" ; req.wide = "jingdong" ; req.high = "jingdong" ; req.weight = "jingdong" ; req.costprice = "jingdong" ; req.marketprice = "jingdong" ; req.jdprice = "jingdong" ; req.notes = "jingdong" ; req.wareimage = "txt" ; req.packlisting = "jingdong" ; req.service = "jingdong" ; req.skuproperties = "jingdong" ; req.attributes = "jingdong" ; req.skuprices = "jingdong" ; req.skustocks = "jingdong" ; req.propertyalias = "jingdong" ; req.outerid = "jingdong" ; req.ispayfirst = "jingdong" ; req.iscanvat = "jingdong" ; req.isimported = "jingdong" ; req.ishealthproduct = "jingdong" ; req.isshelflife = "jingdong" ; req.shelflifedays = "jingdong" ; req.isserialno = "jingdong" ; req.isappliancescard = "jingdong" ; req.isspecialwet = "jingdong" ; req.warebigsmallmodel = "jingdong" ; req.warepacktype = "jingdong" ; req.inputpids = "jingdong" ; req.inputstrs = "jingdong" ; req.hascheckcode = "jingdong" ; req.adcontent = "jingdong" ; req.listtime = "jingdong" ;
  6.  
  7. WareAddResponse response1 = client.Execute (req, token, DateTime.Now.ToLocalTime());

其中有req.Attributes,req.InputPids这两个的值需要调用attribute这个接口从中获得属性

  1. url, appkey, appsecret这三个是密钥,就不说了,必填字段是req.cid,和req.fields
  1. token, DateTime.Now.ToLocalTime()这三个可以不填

因为我要用到response1里面的skuid,而这个值只能通过response1的Attribute属性获得一个Attribute集合

  1. List<Attribute>list=new <Attribute>();

而运行的时候会发现,即使参数都谢对了,也不会获得数据

原因就是:jdsdk面的Attribute属性和.net框架里面的Attribute重名了,

Attribute在.net里面是abstract,抽象类没有不能被创建对象

最后总结的解决办法是:用Http请求

第一步:首先要组织http请求的url地址

  jd有个api测试工具

  

  1. 当你填完参数,点击"提交测试"的时候会在提交参数一栏显示请求的url复制出来:

主要的搞定,下面我个方法,仅供参考

这是创建请求url的

  1. public static string CreatUrl(string cid)
  2. {
  3. string url;
  4. return url = "https://api.jd.com/routerjson?v=2.0&method=360buy.ware.get.attribute&app_key=" + appKey + "&access_token=" + accessToken + "&360buy_param_json={\"cid\":\"" + cid + "\",\"is_key_prop\":\"\",\"is_sale_prop\":\"\",\"aid\":\"\",\"fields\":\"cid,aid,name\"}&timestamp=" + DateTime.Now.ToString();
  5. }

第二部 :用组织的url去请求,获取数据

  1. public static Dictionary<string, string> GetAttribute(string cid)
  2. {
  3. string url = CreatUrl(cid);
  4.  
  5. Encoding dataEncode = Encoding.UTF8;
  6. HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
  7. webReq.Method = "GET";
  8. webReq.ContentType = "application/x-www-form-urlencoded";
  9. HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
  10. StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  11. string json = sr.ReadToEnd();
  12. int count = JObject.Parse(json)["category_attribute_search_response"]["attributes"].Count();
  13. Dictionary<string, string> dic = new Dictionary<string, string>();
  14. var list = JObject.Parse(json)["category_attribute_search_response"]["attributes"];
  15. for (int i = ; i < count; i++)
  16. {
  17. if (list[i]["name"].ToString() == "ISBN")
  18. {
  19. dic.Add("ISBN", list[i]["aid"].ToString());
  20. }
  21. if (list[i]["name"].ToString() == "版次")
  22. {
  23. dic.Add("版次", list[i]["aid"].ToString());
  24. }
  25. if (list[i]["name"].ToString() == "出版社")
  26. {
  27. dic.Add("出版社", list[i]["aid"].ToString());
  28. }
  29. }
  30.  
  31. return dic;
  32. }

其中有一步骤比较重要,

  1. string json = sr.ReadToEnd();得出来的是json字符串,需要解析
    大体结构是这样的
  1. {
  2. "category_attribute_search_response":
  3. {"code":"","total":,"attributes":
  4. [
  5. {"aid":,"name":"主题词"},
  6. {"aid":,"name":"读者对象"},
  7. {"aid":,"name":"附件"},
  8. {"aid":,"name":"中图法分类号"},
  9. {"aid":,"name":"附件数量"},
  10. {"aid":,"name":"朗读"},
  11. {"aid":,"name":"编纂"},
  12. {"aid":,"name":"注释"},
  13. {"aid":,"name":"口述"},
  14. {"aid":,"name":"整理"},
  15. {"aid":,"name":"品牌"},
  16. {"aid":,"name":"摄影"},
  17. {"aid":,"name":"书写"},
  18. {"aid":,"name":"出版社"},
  19. {"aid":,"name":"包装 "},
  20. {"aid":,"name":"版次"},
  21. {"aid":,"name":"ISBN"},
  22. {"aid":,"name":"印次"},
  23. {"aid":,"name":"印刷时间"},
  24. {"aid":,"name":"页数"},
  25. {"aid":,"name":"字数"},
  26. {"aid":,"name":"开本"},
  27. {"aid":,"name":"套装数量"},
  28. {"aid":,"name":"出版时间"},
  29. {"aid":,"name":"正文语言"},
  30. {"aid":,"name":"绘者"},
  31. {"aid":,"name":"校对"},
  32. {"aid":,"name":"编者"},
  33. {"aid":,"name":"译者"},
  34. {"aid":,"name":"外文名"},
  35. {"aid":,"name":"著者"},
  36. {"aid":,"name":"用纸"},
  37. {"aid":,"name":"丛书名"},
  38. {"aid":,"name":"品相"}
  39. ]
  40. }
  41.  
  42. }

京东sdk商家上架接口调用问题总结的更多相关文章

  1. 京东sdk商家上架接口调用问题总结(更新中...)

    前言: 最近在做商家发布产品,调用京东sdk,发现问题很多,而且还是在我同事的帮助下完成的,摸索中,菜鸟还请高手门多多提携才好,入正题 首先是引用jd的sdk啦,京东sdk中发布商品需要调用一个 36 ...

  2. iOS app支付宝接口调用的一点总结(补充支付宝SDK&Demo下载地址)

    由于app内需要用到支付功能,选择了当前最流行的支付宝进行支付.在进行内嵌支付宝功能开发时,被它狠狠的耍了一把. 根据支付宝开发文档,参考demo代码.将相关支付功能加到了自己的代码中.一些根据文档来 ...

  3. 转:iOS app支付宝接口调用的一点总结(补充支付宝SDK&Demo下载地址)

    iosiOSIOS文档服务器测试电话 由于app内需要用到支付功能,选择了当前最流行的支付宝进行支付.在进行内嵌支付宝功能开发时,被它狠狠的耍了一把. 根据支付宝开发文档,参考demo代码.将相关支付 ...

  4. asp.net mvc短信接口调用——阿里大于API开发心得

    互联网上有许多公司提供短信接口服务,诸如网易云信.阿里大于等等.我在自己项目里需要使用到短信服务起到通知作用,实际开发周期三天,完成配置.开发和使用,总的说,阿里大于提供的接口易于开发,非常的方便,短 ...

  5. Spring框架下的 “接口调用、MVC请求” 调用参数、返回值、耗时信息输出

    主要拦截前端或后天的请求,打印请求方法参数.返回值.耗时.异常的日志.方便开发调试,能很快定位到问题出现在哪个方法中. 前端请求拦截,mvc的拦截器 import java.util.Date; im ...

  6. OpenCV4Android开发之旅(一)----OpenCV2.4简介及 app通过Java接口调用OpenCV的示例

    转自:  http://blog.csdn.net/yanzi1225627/article/details/16917961 开发环境:windows+ADT Bundle+CDT+OpenCV-2 ...

  7. 微信公众号开发C#系列-4、获取接口调用凭证

    概述 获取接口调用凭证实质就是获取access_token.在微信接口开发中,许多服务的使用都离不开Access Token,Access Token相当于打开这些服务的钥匙,正常情况下会在7200秒 ...

  8. RTX Server SDK跨服务器如何调用

    1.   确认安装RTX Server SDK在开发的机器上必须确认已经安装了RTX Server SDK,并且与RTX Server的版本要一致.该计算机后面我们简称SDK计算机. 2.   步骤2 ...

  9. PHP SDK短信接口

    /** * sdk 短信接口 * @param $tel 手机号 * @param $content 短信内容 * @return bool */ public function telSDK($te ...

随机推荐

  1. Method for sub-pixel texture mapping and filtering

    BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a method for ...

  2. 给定正整数n,计算出n个元素的集合{1,2,....,n}能够划分为多少个不同的非空集合

    给定正整数n,计算出n个元素的集合{1,2,....,n}能够划分为多少个不同的非空集合 附源码: #include<iostream> using namespace std; int ...

  3. 利用WPF建立自己的3d gis软件(非axhost方式)(八)拖动一个UI到地球上

    原文:利用WPF建立自己的3d gis软件(非axhost方式)(八)拖动一个UI到地球上 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bPew ...

  4. 实战caffe多标签分类——汽车品牌与车辆外观(C++接口)[详细实现+数据集]

    前言 很多地方我们都需要用到多标签分类,比如一张图片,上面有只蓝猫,另一张图片上面有一只黄狗,那么我们要识别的时候,就可以采用多标签分类这一思想了.任务一是识别出这个到底是猫还是狗?(类型)任务二是识 ...

  5. android中滑动SQLite数据库分页加载

    今天用到了android中滑动SQlit数据库分页加载技术,写了个测试工程,将代码贴出来和大家交流一下: MainActivity package com.example.testscrollsqli ...

  6. java学习笔记(7)——I/O流

    一.File类 File(File parent, String child); File(Stirng filename); ------------------------------------ ...

  7. 将 WPF、UWP 以及其他各种类型的旧 csproj 迁移成基于 Microsoft.NET.Sdk 的新 csproj

    原文 将 WPF.UWP 以及其他各种类型的旧 csproj 迁移成基于 Microsoft.NET.Sdk 的新 csproj 写过 .NET Standard 类库或者 .NET Core 程序的 ...

  8. Linux性能测试 iostat命令

    Linux系统出现了性能问题,一般我们可以通过top.iostat.free.vmstat等命令 来查看初步定位问题.其中iostat可以给我们提供丰富的IO状态数据.iostat 由 Red Hat ...

  9. python下载图片(3)

    # -*- coding: utf-8 -*-"""some function by metaphy,2007-04-03,copyleftversion 0.2&quo ...

  10. ASP.NET Core 视图 - ASP.NET Core 基础教程 - 简单教程,简单编程

    原文:ASP.NET Core 视图 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 视图 花了几章节,终于把 ASP.NET Core MVC 中的 C 控 ...