Foxtable(狐表)用户栏目专家坐堂 → 关于一个JSON的解析问题


  共有4062人关注过本帖树形打印复制链接

主题:关于一个JSON的解析问题

帅哥哟,离线,有人找我吗?
huangxueyao
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:443 积分:3530 威望:0 精华:0 注册:2013/2/9 12:45:00
关于一个JSON的解析问题  发帖心情 Post By:2021/6/1 23:10:00 [只看该作者]

调用的目标发生了异常。
Accessed JArray values with invalid key value: "records". Int32 array index expected.

出现这个错误是什么意思?

 回到顶部
帅哥哟,离线,有人找我吗?
huangxueyao
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:443 积分:3530 威望:0 精华:0 注册:2013/2/9 12:45:00
  发帖心情 Post By:2021/6/1 23:11:00 [只看该作者]

{"success":true,"data":{"records":[{"prId":803524,"acId":772918,"preId":5379960,"sku":"0789109","dailySaleTime":null,"tmBuyStart":"2021-05-30 00:00:00","tmBuyEnd":"2021-05-30 23:00:00","tmShowStart":"2021-05-30 00:00:00","tmShowEnd":"2021-05-30 23:00:00","adUrl":"https://image.xsyxsc.com/item/storePromotion/poster/20210529/MWdqSzY=.jpg","prName":"三户 涪陵香辣榨菜丝  60g/包 5包/袋 2袋/组","tmPickUp":"2021-05-31 16:00:00","limitQty":0.0,"ulimitQty":0.0,"marketAmt":17.0,"saleAmt":8.9,"prType":"CHOICE","areaId":105,"shelfLife":"常温18个月","hasLive":false,"productStorage":0,"videoUrl":"","hasPriceList":false,"skuSn":"005377699","marketAmtSourceType":"参考超市","vesName":"善食荟食品","attrs":[{"name":"规格","attr":"60g/包 5包/袋 2袋/组"}],"specialSale":"FALSE","saleStatus":null,"windowId":100,"sortSeq":99999,"existsInAct":false,"verificationCode":false,"spuSn":"20210529773314105368799","isNextDayPickUp":true,"assignType":0,"imgUrl":"http://image.xsyxsc.com/item/20210413/MThzOVQ=.jpg","utvList":null,"hasExplainVideo":false,"explainUtvId":null,"hasCookbook":false,"productRealType":null,"marketingDataDto":{"spuSn":"20210529773314105368799","saleQty":51.0,"daySaleQty":51.0,"folQty":1361,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":77,"salePct":-0.1,"saleQtyTotal":"100+","dailySaleQtyTotal":"100+","saleRemain":-1,"wantBuyQtyTotal":"100+","saleLimitType":null},"eskuSn":"00202105291057733145358699"},{"prId":784575,"acId":773019,"preId":5383844,"sku":"0769723","dailySaleTime":null,"tmBuyStart":"2021-05-30 00:00:00","tmBuyEnd":"2021-05-30 23:00:00","tmShowStart":"2021-05-30 00:00:00","tmShowEnd":"2021-05-30 23:00:00","adUrl":"https://image.xsyxsc.com/item/storePromotion/poster/20210529/MWdrTDg=.jpg","prName":"玉蕾 橄榄菜 168g/瓶 2瓶/组  送180g辣味萝卜1瓶","tmPickUp":"2021-05-31 16:00:00","limitQty":0.0,"ulimitQty":0.0,"marketAmt":18.9,"saleAmt":10.9,"prType":"CHOICE","areaId":105,"shelfLife":"常温15个月","hasLive":false,"productStorage":0,"videoUrl":"","hasPriceList":false,"skuSn":"005382354","marketAmtSourceType":"参考超市","vesName":"善食荟食品","attrs":[{"name":"规格","attr":"168g/瓶 2瓶/组  送180g辣味萝卜1瓶"}],"specialSale":"FALSE","saleStatus":null,"windowId":100,"sortSeq":99999,"existsInAct":false,"verificationCode":false,"spuSn":"20210529749442105373454","isNextDayPickUp":true,"assignType":0,"imgUrl":"http://image.xsyxsc.com/primaryImageList/20200511/100percent_26abeecd-e7ce-4fa3-8524-8204b5ca6c7e1589168760389.jpg","utvList":null,"hasExplainVideo":false,"explainUtvId":null,"hasCookbook":false,"productRealType":null,"marketingDataDto":{"spuSn":"20210529749442105373454","saleQty":67.0,"daySaleQty":67.0,"folQty":1352,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":84,"salePct":-0.1,"saleQtyTotal":"100+","dailySaleQtyTotal":"100+","saleRemain":-1,"wantBuyQtyTotal":"100+","saleLimitType":null},"eskuSn":"00202105291057494425363357"},{"prId":694709,"acId":772996,"preId":5382743,"sku":"0676223","dailySaleTime":null,"tmBuyStart":"2021-05-30 00:00:00","tmBuyEnd":"2021-05-30 23:00:00","tmShowStart":"2021-05-30 00:00:00","tmShowEnd":"2021-05-30 23:00:00","adUrl":"https://image.xsyxsc.com/item/storePromotion/poster/20210529/MWdrdUE=.jpg","prName":"香贡世家 马坝油香粘米  15kg/包","tmPickUp":"2021-05-31 16:00:00","limitQty":2000.0,"ulimitQty":10.0,"marketAmt":72.0,"saleAmt":67.8,"prType":"CHOICE","areaId":105,"shelfLife":"常温180天","hasLive":false,"productStorage":0,"videoUrl":"","hasPriceList":false,"skuSn":"005380679","marketAmtSourceType":"参考厂家定价","vesName":"鹰南农业","attrs":[{"name":"规格","attr":"15kg/包"}],"specialSale":"FALSE","saleStatus":null,"windowId":100,"sortSeq":99999,"existsInAct":false,"verificationCode":false,"spuSn":"20210529471169105371779","isNextDayPickUp":true,"assignType":0,"imgUrl":"http://image.xsyxsc.com/item/20210111/VktCOA==.jpg","utvList":null,"hasExplainVideo":false,"explainUtvId":null,"hasCookbook":false,"productRealType":null,"marketingDataDto":{"spuSn":"20210529471169105371779","saleQty":67.0,"daySaleQty":67.0,"folQty":1513,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":49,"salePct":0.03,"saleQtyTotal":"100+","dailySaleQtyTotal":"100+","saleRemain":100,"wantBuyQtyTotal":"100+","saleLimitType":"SPUSN_STORE"},"eskuSn":"00202105291054711695361782"},{"prId":740640,"acId":772996,"preId":5382731,"sku":"0724574","dailySaleTime":null,"tmBuyStart":"2021-05-30 00:00:00","tmBuyEnd":"2021-05-30 23:00:00","tmShowStart":"2021-05-30 00:00:00","tmShowEnd":"2021-05-30 23:00:00","adUrl":"https://image.xsyxsc.com/item/storePromotion/poster/20210529/MWdrdXk=.jpg","prName":"井岗一号 虾皇靓粘米 10kg/包","tmPickUp":"2021-05-31 16:00:00","limitQty":4000.0,"ulimitQty":20.0,"marketAmt":76.0,"saleAmt":52.8,"prType":"CHOICE","areaId":105,"shelfLife":"常温12个月","hasLive":false,"productStorage":0,"videoUrl":"","hasPriceList":false,"skuSn":"005380667","marketAmtSourceType":"参考超市","vesName":"国粮米业","attrs":[{"name":"规格","attr":"10kg/包"}],"specialSale":"FALSE","saleStatus":null,"windowId":100,"sortSeq":99999,"existsInAct":false,"verificationCode":false,"spuSn":"20210529471169105371767","isNextDayPickUp":true,"assignType":0,"imgUrl":"http://image.xsyxsc.com/item/20210319/MTQ4dkI=.jpg","utvList":null,"hasExplainVideo":false,"explainUtvId":null,"hasCookbook":false,"productRealType":null,"marketingDataDto":{"spuSn":"20210529471169105371767","saleQty":124.0,"daySaleQty":124.0,"folQty":2241,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":72,"salePct":0.03,"saleQtyTotal":"500+","dailySaleQtyTotal":"500+","saleRemain":200,"wantBuyQtyTotal":"100+","saleLimitType":"SPUSN_STORE"},"eskuSn":"00202105291054711695361770"},{"prId":793232,"acId":772985,"preId":5381853,"sku":"0778606","dailySaleTime":null,"tmBuyStart":"2021-05-30 00:00:00","tmBuyEnd":"2021-05-30 23:00:00","tmShowStart":"2021-05-30 00:00:00","tmShowEnd":"2021-05-30 23:00:00","adUrl":"https://image.xsyxsc.com/item/storePromotion/poster/20210529/MWdrc0I=.jpg","prName":"陈克明 圆挂面  900g/筒","tmPickUp":"2021-05-31 16:00:00","limitQty":0.0,"ulimitQty":0.0,"marketAmt":12.5,"saleAmt":5.99,"prType":"CHOICE","areaId":105,"shelfLife":"常温1年","hasLive":false,"productStorage":0,"videoUrl":"","hasPriceList":false,"skuSn":"005380102","marketAmtSourceType":"参考超市","vesName":"善食荟食品","attrs":[{"name":"规格","attr":"900g/筒"}],"specialSale":"FALSE","saleStatus":null,"windowId":100,"sortSeq":99999,"existsInAct":false,"verificationCode":false,"spuSn":"20210529901248105371202","isNextDayPickUp":true,"assignType":0,"imgUrl":"http://image.xsyxsc.com/primaryImageList/20200429/100percent_f45ca87c-ff49-4281-bf9c-a19286517a3b1588138460453.jpg","utvList":null,"hasExplainVideo":false,"explainUtvId":null,"hasCookbook":false,"productRealType":null,"marketingDataDto":{"spuSn":"20210529901248105371202","saleQty":265.0,"daySaleQty":265.0,"folQty":1816,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":107,"salePct":-0.1,"saleQtyTotal":"500+","dailySaleQtyTotal":"500+","saleRemain":-1,"wantBuyQtyTotal":"500+","saleLimitType":null},"eskuSn":"00202105291059012485361105"},{"prId":764282,"acId":772985,"preId":5381852,"sku":"0748786","dailySaleTime":null,"tmBuyStart":"2021-05-30 00:00:00","tmBuyEnd":"2021-05-30 23:00:00","tmShowStart":"2021-05-30 00:00:00","tmShowEnd":"2021-05-30 23:00:00","adUrl":"https://image.xsyxsc.com/item/storePromotion/poster/20210529/MWdrc0E=.jpg","prName":"陈克明 细挂面  900g/筒","tmPickUp":"2021-05-31 16:00:00","limitQty":0.0,"ulimitQty":0.0,"marketAmt":12.5,"saleAmt":5.99,"prType":"CHOICE","areaId":105,"shelfLife":"常温12个月","hasLive":false,"productStorage":0,"videoUrl":"","hasPriceList":false,"skuSn":"005380101","marketAmtSourceType":"参考超市","vesName":"善食荟食品","attrs":[{"name":"规格","attr":"900g/筒"}],"specialSale":"FALSE","saleStatus":null,"windowId":100,"sortSeq":99999,"existsInAct":false,"verificationCode":false,"spuSn":"20210529901248105371201","isNextDayPickUp":true,"assignType":0,"imgUrl":"http://image.xsyxsc.com/item/20210303/MTFSNXY=.jpg","utvList":null,"hasExplainVideo":false,"explainUtvId":null,"hasCookbook":false,"productRealType":null,"marketingDataDto":{"spuSn":"20210529901248105371201","saleQty":304.0,"daySaleQty":304.0,"folQty":2090,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":130,"salePct":-0.1,"saleQtyTotal":"500+","dailySaleQtyTotal":"500+","saleRemain":-1,"wantBuyQtyTotal":"500+","saleLimitType":null},"eskuSn":"00202105291059012485361104"},{"prId":770643,"acId":772985,"preId":5381851,"sku":"0755266","dailySaleTime":null,"tmBuyStart":"2021-05-30 00:00:00","tmBuyEnd":"2021-05-30 23:00:00","tmShowStart":"2021-05-30 00:00:00","tmShowEnd":"2021-05-30 23:00:00","adUrl":"https://image.xsyxsc.com/item/storePromotion/poster/20210529/MWdrc3o=.jpg","prName":"陈克明 宽挂面    900g/筒","tmPickUp":"2021-05-31 16:00:00","limitQty":0.0,"ulimitQty":0.0,"marketAmt":12.5,"saleAmt":5.99,"prType":"CHOICE","areaId":105,"shelfLife":"常温12个月","hasLive":false,"productStorage":0,"videoUrl":"","hasPriceList":false,"skuSn":"005380100","marketAmtSourceType":"参考超市","vesName":"善食荟食品","attrs":[{"name":"规格","attr":"900g/筒"}],"specialSale":"FALSE","saleStatus":null,"windowId":100,"sortSeq":99999,"existsInAct":false,"verificationCode":false,"spuSn":"20210529901248105371200","isNextDayPickUp":true,"assignType":0,"imgUrl":"http://image.xsyxsc.com/item/20200908/S2pQRQ==.jpg","utvList":null,"hasExplainVideo":false,"explainUtvId":null,"hasCookbook":false,"productRealType":null,"marketingDataDto":{"spuSn":"20210529901248105371200","saleQty":555.0,"daySaleQty":555.0,"folQty":2322,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":148,"salePct":-0.1,"saleQtyTotal":"1000+","dailySaleQtyTotal":"1000+","saleRemain":-1,"wantBuyQtyTotal":"500+","saleLimitType":null},"eskuSn":"00202105291059012485361103"},{"prId":735318,"acId":772921,"preId":5380083,"sku":"0718905","dailySaleTime":null,"tmBuyStart":"2021-05-30 00:00:00","tmBuyEnd":"2021-05-30 23:00:00","tmShowStart":"2021-05-30 00:00:00","tmShowEnd":"2021-05-30 23:00:00","adUrl":"https://image.xsyxsc.com/item/storePromotion/poster/20210529/MWdqSGM=.jpg","prName":"乐米乐 金健御府香丝苗米  15kg/包","tmPickUp":"2021-05-31 16:00:00","limitQty":4000.0,"ulimitQty":10.0,"marketAmt":94.9,"saleAmt":74.8,"prType":"CHOICE","areaId":105,"shelfLife":"常温12个月","hasLive":false,"productStorage":0,"videoUrl":"","hasPriceList":false,"skuSn":"005378184","marketAmtSourceType":"参考厂家定价","vesName":"乐米乐","attrs":[{"name":"规格","attr":"15kg/包"}],"specialSale":"FALSE","saleStatus":null,"windowId":100,"sortSeq":99999,"existsInAct":false,"verificationCode":false,"spuSn":"20210529386946105369284","isNextDayPickUp":true,"assignType":0,"imgUrl":"http://image.xsyxsc.com/item/20201122/UWFaWg==.jpg","utvList":null,"hasExplainVideo":false,"explainUtvId":null,"hasCookbook":false,"productRealType":null,"marketingDataDto":{"spuSn":"20210529386946105369284","saleQty":24.0,"daySaleQty":24.0,"folQty":959,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":13,"salePct":0.01,"saleQtyTotal":"100+","dailySaleQtyTotal":"100+","saleRemain":50,"wantBuyQtyTotal":"100+","saleLimitType":"SPUSN_STORE"},"eskuSn":"00202105291053869465359184"}],"spuSns":null},"rspCode":"success","rspDesc":"操作成功"}

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110750 积分:563676 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/6/2 8:30:00 [只看该作者]

贴出具体代码呀。提示是索引不正确,比如records数组有2项,ja(0)和ja(1)是正常的,ja(2)就出错了

 回到顶部
帅哥哟,离线,有人找我吗?
huangxueyao
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:443 积分:3530 威望:0 精华:0 注册:2013/2/9 12:45:00
  发帖心情 Post By:2021/6/2 11:26:00 [只看该作者]

For Each jt As JToken In jo("data")("records")
        dr("updatetime") = Date.Today
        dr("prId") = jt("prId").tostring
        dr("prName") = jt("prName").tostring
    Next

以上代码我没看出什么问题啊

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110750 积分:563676 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/6/2 11:43:00 [只看该作者]

调试一下自己代码,看是哪一句代码出错

我把2楼的json保存下来测试没有问题呀。

Dim s As String = FileSys.ReadAllText("D:\问题\111.json")
Dim jo As JObject = Jobject.Parse(s)

For Each jt As JToken In jo("data")("records")
    Output.Show( jt("prId").tostring)
    Output.Show( jt("prName").tostring)
Next

 回到顶部
帅哥哟,离线,有人找我吗?
huangxueyao
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:443 积分:3530 威望:0 精华:0 注册:2013/2/9 12:45:00
  发帖心情 Post By:2021/6/5 11:01:00 [只看该作者]

{"success":true,"data":[{"spuSn":"20210602471169105493633","saleQty":510.0,"daySaleQty":510.0,"folQty":4531,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":63,"salePct":-0.1,"saleQtyTotal":"1000+","dailySaleQtyTotal":"1000+","saleRemain":-1,"wantBuyQtyTotal":"100+","saleLimitType":null},{"spuSn":"20210602471169105493632","saleQty":933.0,"daySaleQty":933.0,"folQty":5916,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":72,"salePct":-0.1,"saleQtyTotal":"1000+","dailySaleQtyTotal":"1000+","saleRemain":-1,"wantBuyQtyTotal":"100+","saleLimitType":null},{"spuSn":"20210602471169105493658","saleQty":108.0,"daySaleQty":108.0,"folQty":2378,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":18,"salePct":-0.1,"saleQtyTotal":"500+","dailySaleQtyTotal":"500+","saleRemain":-1,"wantBuyQtyTotal":"100+","saleLimitType":null},{"spuSn":"20210602386946105493520","saleQty":5.0,"daySaleQty":5.0,"folQty":878,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":1,"salePct":0.02,"saleQtyTotal":"10+","dailySaleQtyTotal":"10+","saleRemain":295,"wantBuyQtyTotal":"10+","saleLimitType":null},{"spuSn":"20210602386946105493521","saleQty":23.0,"daySaleQty":23.0,"folQty":1245,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":1,"salePct":-0.1,"saleQtyTotal":"100+","dailySaleQtyTotal":"100+","saleRemain":-1,"wantBuyQtyTotal":"10+","saleLimitType":null},{"spuSn":"20210602386946105493518","saleQty":204.0,"daySaleQty":204.0,"folQty":2805,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":15,"salePct":0.34,"saleQtyTotal":"500+","dailySaleQtyTotal":"500+","saleRemain":396,"wantBuyQtyTotal":"100+","saleLimitType":null},{"spuSn":"20210602386946105493519","saleQty":3.0,"daySaleQty":3.0,"folQty":940,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":2,"salePct":0.01,"saleQtyTotal":"10+","dailySaleQtyTotal":"10+","saleRemain":297,"wantBuyQtyTotal":"10+","saleLimitType":null},{"spuSn":"20210602773314105492688","saleQty":419.0,"daySaleQty":419.0,"folQty":3273,"consumers":null,"viewNum":0,"likeNum":0,"wantBuyQty":14,"salePct":-0.1,"saleQtyTotal":"500+","dailySaleQtyTotal":"500+","saleRemain":-1,"wantBuyQtyTotal":"100+","saleLimitType":null}],"rspCode":"success","rspDesc":"操作成功"}


解析对象会遇到以上JSON数据,应该怎样识别??

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110750 积分:563676 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/6/5 11:26:00 [只看该作者]

json格式不一致,要根据不同的的格式使用不同的代码

For Each jt As JToken In jo("data")

 回到顶部