我在获取pythonjson模块来解析walmart openapi生成的JSON信息时遇到了一些问题。
我可以从项目的url中以字符串形式检索JSON文件,如下所示:
print(raw_json[0])
b'{
"itemId":43090845,
"parentItemId":43090845,
"name":"Better Homes and Gardens Owl Memory Foam Bath Rug, 20\\" x 30\\"",
"msrp":15.88,
"salePrice":14.88,
"upc":"040773068722",
"categoryPath":"Home/Bath/Bath Rugs & Mats",
"shortDescription":"Pamper your feet with this Memory Foam bath mat from Mohawk Home. All synthetic textiles enable it to stand up to moisture. Slip-resistant backing makes it extra safe and fast drying. Bath rug is machine washable.",
"longDescription":"<br><b>Better Homes and Gardens Owl Memory Foam Bath Rug, 20" x 30":</b><ul><li>Machine washable</li><li>Slip-resistant backing</li><li>Fast drying</li><li>Soft to touch</li><li>Material Content: Polyester</li><li>Better Homes and Garden bath rugs is extra safe</li></ul>",
"brandName":"Better Homes & Gardens",
"thumbnailImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=100& odnWidth=100&odnBg=FFFFFF",
"mediumImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=180& odnWidth=180&odnBg=FFFFFF",
"largeImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=450& odnWidth=450&odnBg=FFFFFF",
"productTrackingUrl":"http://linksynergy.walmart.com/fs- bin/click?id=|LSNID|&offerid=223073.7200&type=14&catid=8&subid=0&hid=7200& tmpid=1082&RD_PARM1=https%253A%252F%252Fwww.walmart.com%252Fip%252FBetter- Homes-and-Gardens-Owl-Memory-Foam-Bath-Rug-20- x-30%252F43090845%253Faffp1%253D3NMsqL2_UxcE1HIonNkB- L5B02IQEPQWawum0w3ENkc%2526affilsrc%253Dapi",
"ninetySevenCentShipping":false,
"standardShipRate":5.99,
"size":"20\\" x 30\\"",
"color":"Brown",
"marketplace":false,
"shipToStore":true,
"freeShipToStore":true,
"modelNumber":"BH15-005-599-01",
"productUrl":"http://c.affil.walmart.com/t/api01?l=https%3A%2F %2Fwww.walmart.com%2Fip%2FBetter-Homes-and-Gardens-Owl-Memory-Foam-Bath- Rug-20-x-30%2F43090845%3Faffp1%3D3NMsqL2_UxcE1HIonNkB- L5B02IQEPQWawum0w3ENkc%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlya pi",
"customerRating":"4.4",
"numReviews":5,
"customerRatingImage":"http://i2.walmartimages.com/i/CustRating /4_4.gif",
"categoryNode":"4044_539095_920259",
"rhid":"30609",
"bundle":false,
"clearance":false,
"preOrder":false,
"stock":"NOT_AVAILABLE",
"attributes":{
"color":"Brown",
"ironBankCategory":"Home Decor",
"size":"20\\" x 30\\""
},
"gender":"Unisex",
"addToCartUrl":"http://c.affil.walmart.com/t/api01?l=http%3A%2F %2Faffil.walmart.com%2Fcart%2FaddToCart%3Fitems%3D43090845%7C1%26affp1%3D3NMs qL2_UxcE1HIonNkB- L5B02IQEPQWawum0w3ENkc%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlya pi",
"affiliateAddToCartUrl":"http://linksynergy.walmart.com/fs- bin/click?id=|LSNID|&offerid=223073.7200&type=14&catid=8&subid=0&hid=7200& tmpid=1082& RD_PARM1=http%253A%252F%252Faffil.walmart.com%252Fcart%252FaddToCart%253Fitem s%253D43090845%257C1%2526affp1%253D3NMsqL2_UxcE1HIonNkB- L5B02IQEPQWawum0w3ENkc%2526affilsrc%253Dapi",
"freeShippingOver35Dollars":true,
"imageEntities":[
{
"thumbnailImage":"https://i5.walmartimages.com/asr/2a6072b1- d71a-4dd4-8cbb- afb358bc04d2_1.e766841c15741606236fb13fec3aa347.jpeg?odnHeight=100& odnWidth=100&odnBg=FFFFFF",
"mediumImage":"https://i5.walmartimages.com/asr/2a6072b1- d71a-4dd4-8cbb- afb358bc04d2_1.e766841c15741606236fb13fec3aa347.jpeg?odnHeight=180& odnWidth=180&odnBg=FFFFFF",
"largeImage":"https://i5.walmartimages.com/asr/2a6072b1- d71a-4dd4-8cbb- afb358bc04d2_1.e766841c15741606236fb13fec3aa347.jpeg?odnHeight=450& odnWidth=450&odnBg=FFFFFF",
"entityType":"SECONDARY"
},
{
"thumbnailImage":"https://i5.walmartimages.com /asr/d1dbd2e0-8bd1-4e12-ac2b- bfa24cb6e980_1.1083a714bcf34400fdab2b1dc19df4a3.jpeg?odnHeight=100& odnWidth=100&odnBg=FFFFFF",
"mediumImage":"https://i5.walmartimages.com /asr/d1dbd2e0-8bd1-4e12-ac2b- bfa24cb6e980_1.1083a714bcf34400fdab2b1dc19df4a3.jpeg?odnHeight=180& odnWidth=180&odnBg=FFFFFF",
"largeImage":"https://i5.walmartimages.com /asr/d1dbd2e0-8bd1-4e12-ac2b- bfa24cb6e980_1.1083a714bcf34400fdab2b1dc19df4a3.jpeg?odnHeight=450& odnWidth=450&odnBg=FFFFFF",
"entityType":"SECONDARY"
},
{
"thumbnailImage":"https://i5.walmartimages.com /asr/56639088-94cb-46b3-8a3c- 750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=100& odnWidth=100&odnBg=FFFFFF",
"mediumImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=180& odnWidth=180&odnBg=FFFFFF",
"largeImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=450& odnWidth=450&odnBg=FFFFFF",
"entityType":"PRIMARY"
}
],
"availableOnline":false
}'
->我没有做任何更改API的输出,但是我删除了似乎导入到表中的b“…”部分。
clean_json = []
for i in rawJson:
temp = i[2:-1]
clean_json.append(temp)
实际上,它只删除了b’…”部分,你可以在这里看到:
print(clean_json[0])
{
"itemId":43090845,
"parentItemId":43090845,
"name":"Better Homes and Gardens Owl Memory Foam Bath Rug, 20\\" x 30\\"",
"msrp":15.88,
"salePrice":14.88,
"upc":"040773068722",
"categoryPath":"Home/Bath/Bath Rugs & Mats",
"shortDescription":"Pamper your feet with this Memory Foam bath mat from Mohawk Home. All synthetic textiles enable it to stand up to moisture. Slip-resistant backing makes it extra safe and fast drying. Bath rug is machine washable.",
"longDescription":"<br><b>Better Homes and Gardens Owl Memory Foam Bath Rug, 20" x 30":</b><ul><li>Machine washable</li><li>Slip-resistant backing</li><li>Fast drying</li><li>Soft to touch</li><li>Material Content: Polyester</li><li>Better Homes and Garden bath rugs is extra safe</li></ul>",
"brandName":"Better Homes & Gardens",
"thumbnailImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=100& odnWidth=100&odnBg=FFFFFF",
"mediumImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=180& odnWidth=180&odnBg=FFFFFF",
"largeImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=450& odnWidth=450&odnBg=FFFFFF",
"productTrackingUrl":"http://linksynergy.walmart.com/fs- bin/click?id=|LSNID|&offerid=223073.7200&type=14&catid=8&subid=0&hid=7200& tmpid=1082&RD_PARM1=https%253A%252F%252Fwww.walmart.com%252Fip%252FBetter- Homes-and-Gardens-Owl-Memory-Foam-Bath-Rug-20- x-30%252F43090845%253Faffp1%253D3NMsqL2_UxcE1HIonNkB- L5B02IQEPQWawum0w3ENkc%2526affilsrc%253Dapi",
"ninetySevenCentShipping":false,
"standardShipRate":5.99,
"size":"20\\" x 30\\"",
"color":"Brown",
"marketplace":false,
"shipToStore":true,
"freeShipToStore":true,
"modelNumber":"BH15-005-599-01",
"productUrl":"http://c.affil.walmart.com/t/api01?l=https%3A%2F %2Fwww.walmart.com%2Fip%2FBetter-Homes-and-Gardens-Owl-Memory-Foam-Bath- Rug-20-x-30%2F43090845%3Faffp1%3D3NMsqL2_UxcE1HIonNkB- L5B02IQEPQWawum0w3ENkc%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlya pi",
"customerRating":"4.4",
"numReviews":5,
"customerRatingImage":"http://i2.walmartimages.com/i/CustRating /4_4.gif",
"categoryNode":"4044_539095_920259",
"rhid":"30609",
"bundle":false,
"clearance":false,
"preOrder":false,
"stock":"NOT_AVAILABLE",
"attributes":{
"color":"Brown",
"ironBankCategory":"Home Decor",
"size":"20\\" x 30\\""
},
"gender":"Unisex",
"addToCartUrl":"http://c.affil.walmart.com/t/api01?l=http%3A%2F %2Faffil.walmart.com%2Fcart%2FaddToCart%3Fitems%3D43090845%7C1%26affp1%3D3NMs qL2_UxcE1HIonNkB- L5B02IQEPQWawum0w3ENkc%26affilsrc%3Dapi%26veh%3Daff%26wmlspartner%3Dreadonlya pi",
"affiliateAddToCartUrl":"http://linksynergy.walmart.com/fs- bin/click?id=|LSNID|&offerid=223073.7200&type=14&catid=8&subid=0&hid=7200& tmpid=1082& RD_PARM1=http%253A%252F%252Faffil.walmart.com%252Fcart%252FaddToCart%253Fitem s%253D43090845%257C1%2526affp1%253D3NMsqL2_UxcE1HIonNkB- L5B02IQEPQWawum0w3ENkc%2526affilsrc%253Dapi",
"freeShippingOver35Dollars":true,
"imageEntities":[
{
"thumbnailImage":"https://i5.walmartimages.com/asr/2a6072b1- d71a-4dd4-8cbb- afb358bc04d2_1.e766841c15741606236fb13fec3aa347.jpeg?odnHeight=100& odnWidth=100&odnBg=FFFFFF",
"mediumImage":"https://i5.walmartimages.com/asr/2a6072b1- d71a-4dd4-8cbb- afb358bc04d2_1.e766841c15741606236fb13fec3aa347.jpeg?odnHeight=180& odnWidth=180&odnBg=FFFFFF",
"largeImage":"https://i5.walmartimages.com/asr/2a6072b1- d71a-4dd4-8cbb- afb358bc04d2_1.e766841c15741606236fb13fec3aa347.jpeg?odnHeight=450& odnWidth=450&odnBg=FFFFFF",
"entityType":"SECONDARY"
},
{
"thumbnailImage":"https://i5.walmartimages.com /asr/d1dbd2e0-8bd1-4e12-ac2b- bfa24cb6e980_1.1083a714bcf34400fdab2b1dc19df4a3.jpeg?odnHeight=100& odnWidth=100&odnBg=FFFFFF",
"mediumImage":"https://i5.walmartimages.com /asr/d1dbd2e0-8bd1-4e12-ac2b- bfa24cb6e980_1.1083a714bcf34400fdab2b1dc19df4a3.jpeg?odnHeight=180& odnWidth=180&odnBg=FFFFFF",
"largeImage":"https://i5.walmartimages.com /asr/d1dbd2e0-8bd1-4e12-ac2b- bfa24cb6e980_1.1083a714bcf34400fdab2b1dc19df4a3.jpeg?odnHeight=450& odnWidth=450&odnBg=FFFFFF",
"entityType":"SECONDARY"
},
{
"thumbnailImage":"https://i5.walmartimages.com /asr/56639088-94cb-46b3-8a3c- 750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=100& odnWidth=100&odnBg=FFFFFF",
"mediumImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=180& odnWidth=180&odnBg=FFFFFF",
"largeImage":"https://i5.walmartimages.com/asr/56639088-94cb- 46b3-8a3c-750633ade144_1.74c9173baaca23617a1086156ee5f976.jpeg?odnHeight=450& odnWidth=450&odnBg=FFFFFF",
"entityType":"PRIMARY"
}
],
"availableOnline":false
}
parsed_json = []
for i in clean_json:
temp = json.loads(r"""i""")
parsed_json.append(temp)
然而,我不断得到这个错误:
raise JSONDecodeError("Expecting value", s, err.value) from None
JSONDecodeError: Expecting value