自学的菜鸟 2021-11-11 17:38 采纳率: 61.6%
浏览 305
已结题

模拟淘宝请求从淘宝接口获取到的json数据如何解析sku

返回的数据有多个sku,如何将库存信息和价格信息的键名和sku(black,white这样的字符串)对应起来这是商品链接https$://item.taobao.com/item.htm?id=659530016794
这个字典里sku是用数字;20549:672896057;1627207:3327837;这样的键名表达的,而商品链接里面sku是black,white,黑色,白色这样的字符串,如何判断识别这个键名代表哪个sku字符串
下面是sku的价格信息

  "originalPrice": {
      ";20549:69326249;1627207:3331185;": {
          "price": "842.50"
      },
      ";20549:64797379;1627207:3331185;": {
          "price": "844.00"
      },
      "def": {
          "price": "836.00-944.00"
      },
      ";20549:72380707;1627207:3327837;": {
          "price": "937.00"
      },
      ";20549:225078235;1627207:3327837;": {
          "price": "943.00"
      },
      ";20549:672896055;1627207:3327837;": {
          "price": "938.50"
      },
      ";20549:229418985;1627207:3331185;": {
          "price": "840.00"
      },
      ";20549:473680452;1627207:3327837;": {
          "price": "942.00"
      },
      ";20549:672896057;1627207:3331185;": {
          "price": "840.50"
      },
      ";20549:418624880;1627207:3331185;": {
          "price": "839.00"
      },
      ";20549:407396361;1627207:3327837;": {
          "price": "941.00"
      },
      ";20549:672896053;1627207:3331185;": {
          "price": "836.50"
      },
      ";20549:103189693;1627207:3327837;": {
          "price": "938.00"
      },
      ";20549:418624880;1627207:3327837;": {
          "price": "939.00"
      },
      ";20549:407396361;1627207:3331185;": {
          "price": "841.00"
      },
      ";20549:225078235;1627207:3331185;": {
          "price": "843.00"
      },
      ";20549:64797379;1627207:3327837;": {
          "price": "944.00"
      },
      ";20549:229418985;1627207:3327837;": {
          "price": "940.00"
      },
      ";20549:59280855;1627207:3327837;": {
          "price": "936.00"
      },
      ";20549:72380707;1627207:3331185;": {
          "price": "837.00"
      },
      ";20549:69326249;1627207:3327837;": {
          "price": "942.50"
      },
      ";20549:473680452;1627207:3331185;": {
          "price": "842.00"
      },
      ";20549:103189693;1627207:3331185;": {
          "price": "838.00"
      },
      ";20549:59280855;1627207:3331185;": {
          "price": "836.00"
      },
      ";20549:672896053;1627207:3327837;": {
          "price": "936.50"
      },
      ";20549:672896057;1627207:3327837;": {
          "price": "940.50"
      },
      ";20549:672896055;1627207:3331185;": {
          "price": "838.50"
      }
  },

下面是sku的库存信息

 "dynStock": {
     "holdQuantity": 0,
     "sellableQuantity": 260,
     "sku": {
         ";20549:69326249;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:64797379;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:72380707;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:225078235;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:672896055;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:229418985;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:473680452;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:672896057;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:418624880;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:407396361;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:672896053;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:103189693;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:418624880;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:407396361;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:225078235;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:64797379;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:229418985;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:59280855;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:72380707;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:69326249;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:473680452;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:103189693;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:59280855;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:672896053;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:672896057;1627207:3327837;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         },
         ";20549:672896055;1627207:3331185;": {
             "holdQuantity": 0,
             "oversold": false,
             "sellableQuantity": 10,
             "stock": 10
         }
     },

  • 写回答

3条回答 默认 最新

  • CSDN专家-showbo 2021-11-11 18:23
    关注

    淘宝返回的数据是jsonp,需要替换下回调的相关信息后,用json_deocde转对象后遍历添加价格到库存里面。前面的一串数字键名称对应什么待研究。。先贴出来

    img

    <meta charset="utf-8">
    <?php
    $cookie="thw=cn; t=6ebd6eb7a9b120df58bf2093ede6b16a; ubn=p; enc=wc%2BKVvyT4b%2Bu%2BcatDRWhRsfSHlmTQ0fzmz%2FB7dHFhcZrEaKabs3hFxfTgOFFvufvCMcGlZ13uUUbhpeDdUXpOg%3D%3D; ali_apache_id=33.5.149.179.1619605199817.391975.4; x=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0; UM_distinctid=17b4e23b65b63f-0c637435899954-376b4502-1fa400-17b4e23b65ca65; ucn=unzbmix; cna=oWf9Fid5YWgCASdIeX10aVIk; lgc=%5Cu6211%5Cu7231%5Cu4E00%5Cu4F117687; tracknick=%5Cu6211%5Cu7231%5Cu4E00%5Cu4F117687; mt=ci=106_1; hng=CN%7Czh-CN%7CCNY%7C156; miid=4067623771849081648; CNZZDATA1256793290=1567906222-1636258541-%7C1636269341; cookie2=4913ba4c059ec43f049a7758e9f2d6b4; _tb_token_=7ed5eeef55159; v=0; _samesite_flag_=true; cancelledSubSites=empty; dnk=%5Cu6211%5Cu7231%5Cu4E00%5Cu4F117687; xlly_s=1; sgcookie=E100IGvEMv%2FRPH4dSxqbL40r82MKwthoZiAY2uLrK%2BIz48fV%2BTqfqGzf2q5tsCiydOX3GMpWL8yuLV8ICUa6InAWNH%2FEbZ9lLBp6dIIrq5bpchw%3D; unb=1683510346; uc3=lg2=WqG3DMC9VAQiUQ%3D%3D&nk2=rUs%2BSxDQoytTTcUF&vt3=F8dCujuuSMTRA5I2Gag%3D&id2=Uoe8idbtvqvgnQ%3D%3D; csg=50084703; cookie17=Uoe8idbtvqvgnQ%3D%3D; skt=9309744b77f11045; existShop=MTYzNjM2MDczNg%3D%3D; uc4=nk4=0%40r7q4CAT3aXdah9eA%2FPHxPw2euVwei8A%3D&id4=0%40UO%2B6bxqoWbhMuyJacKSqqRrvPti7; _cc_=WqG3DMC9EA%3D%3D; _l_g_=Ug%3D%3D; sg=76f; _nk_=%5Cu6211%5Cu7231%5Cu4E00%5Cu4F117687; cookie1=BqR2IrBAXmaISH2hFOvjy7mnA1%2BMMgYmOC%2FtFs138mA%3D; _m_h5_tk=4c58c3ddb0bac6ae8f6c092ae39d2765_1636369027013; _m_h5_tk_enc=936e4d449985bf53ed1c66fc48137590; uc1=pas=0&existShop=true&cookie16=UIHiLt3xCS3yM2h4eKHS9lpEOw%3D%3D&cookie14=Uoe3cc1TvWpO9Q%3D%3D&cookie21=URm48syIZJwcbRltXU0bIA%3D%3D&cookie15=WqG3DMC9VAQiUQ%3D%3D; tfstk=cmBABdG1Sz4ciItRYsFufZZ_iSX1aPa9PmTiBuEanR5xJP0IJscOK9hcoSt61aER.; l=fBIKRJxeOtI-krQ9BO5ahurza77teIdbzsPzaNbMiIeca6shfh0cnNCd6kheddtjgTfqseKzYAkGMdE2llUT5x_r-ZEEOdq55299-bpU-L5..; isg=BGxsnInkIbcmOgvzBlSb1wRAPUqeJRDPAb3c_Masz5cj0Q7b7zP9Xewj9Znp2Ugn";
    $referer="https://item.taobao.com/item.htm?id=659530016794";
    $useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36";
    
    $url="https://detailskip.taobao.com/service/getData/1/p1/item/detail/sib.htm?itemId=659530016794&sellerId=1683510346&modules=dynStock,qrcode,viewer,price,duty,xmpPromotion,delivery,activity,fqg,zjys,couponActivity,soldQuantity,page,originalPrice,tradeContract&callback=onSibRequestSuccess";
    
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_REFERER, $referer);//设置来源
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);//设置Cookie
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);//设置user-agent
    //https设置,不需要证书
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $content=curl_exec($ch);
    curl_close($ch);
    
    $content=str_replace("onSibRequestSuccess(","",$content);
    $content=str_replace(");","",$content);
    
    $data=json_decode($content,true);
    
    $dynStocksku=$data['data']['dynStock']['sku'];
    $originalPrice=$data['data']['originalPrice'];
    
    foreach($originalPrice as $k=>$v){//将价格加到库存里面
      if(isset($dynStocksku[$k]))$dynStocksku[$k]['price']=$v['price'];
    }
    echo(json_encode($dynStocksku))
    ?>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月20日
  • 已采纳回答 11月12日
  • 赞助了问题酬金 11月11日
  • 修改了问题 11月11日
  • 展开全部

悬赏问题

  • ¥15 C++数组中找第二小的数字程序纠错
  • ¥50 MATLAB APP 制作出现问题
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e
  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度
  • ¥15 寻找一块做为智能割草机的驱动板(标签-stm32|关键词-m3)
  • ¥15 信息管理系统的查找和排序
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),怎么用读取的电磁传感器信号表示小车所在的位置
  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)