gpt4 book ai didi

Python从urllib请求中解析json

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:20 24 4
gpt4 key购买 nike

我有以下 json,

{
findItemsByKeywordsResponse: [
{
ack: [
"Success"
],
version: [
"1.12.0"
],
timestamp: [
"2012-08-20T21:42:08.532Z"
],
searchResult: [
{
@count: "2",
item: [
{
itemId: [
"380459520121"
],
title: [
"Lenovo ThinkPad T61 Core 2 Duo 2.2GHz 1GB 120GB DVD-RW WiFi Laptop 15" Notebook"
],
globalId: [
"EBAY-US"
],
primaryCategory: [
{
categoryId: [
"177"
],
categoryName: [
"PC Laptops & Netbooks"
]
}
],
galleryURL: [
"http://thumbs2.ebaystatic.com/pict/3804595201214040_1.jpg"
],
viewItemURL: [
"http://www.ebay.com/itm/Lenovo-ThinkPad-T61-Core-2-Duo-2-2GHz-1GB-120GB-DVD-RW-WiFi-Laptop-15-Notebook-/380459520121?pt=Laptops_Nov05"
],
paymentMethod: [
"PayPal",
"VisaMC",
"Discover"
],
autoPay: [
"false"
],
postalCode: [
"55114"
],
location: [
"Saint Paul,MN,USA"
],
country: [
"US"
],
shippingInfo: [
{
shippingType: [
"Calculated"
],
shipToLocations: [
"US"
],
expeditedShipping: [
"true"
],
oneDayShippingAvailable: [
"false"
],
handlingTime: [
"1"
]
}
],
sellingStatus: [
{
currentPrice: [
{
@currencyId: "USD",
__value__: "112.5"
}
],
convertedCurrentPrice: [
{
@currencyId: "USD",
__value__: "112.5"
}
],
bidCount: [
"5"
],
sellingState: [
"Active"
],
timeLeft: [
"P0DT0H18M18S"
]
}
],
listingInfo: [
{
bestOfferEnabled: [
"false"
],
buyItNowAvailable: [
"false"
],
startTime: [
"2012-08-15T22:00:26.000Z"
],
endTime: [
"2012-08-20T22:00:26.000Z"
],
listingType: [
"Auction"
],
gift: [
"false"
]
}
],
returnsAccepted: [
"true"
],
condition: [
{
conditionId: [
"3000"
],
conditionDisplayName: [
"Used"
]
}
],
isMultiVariationListing: [
"false"
]
},
{
itemId: [
"110931951761"
],
title: [
"Dell Latitude D630 Laptop Core Duo 1.8GHz 2GB Ram 60GB HDD Not Complete"
],
globalId: [
"EBAY-US"
],
primaryCategory: [
{
categoryId: [
"177"
],
categoryName: [
"PC Laptops & Netbooks"
]
}
],
galleryURL: [
"http://thumbs2.ebaystatic.com/pict/1109319517614040_2.jpg"
],
viewItemURL: [
"http://www.ebay.com/itm/Dell-Latitude-D630-Laptop-Core-Duo-1-8GHz-2GB-Ram-60GB-HDD-Not-Complete-/110931951761?pt=Laptops_Nov05"
],
paymentMethod: [
"PayPal"
],
autoPay: [
"false"
],
postalCode: [
"17737"
],
location: [
"Hughesville,PA,USA"
],
country: [
"US"
],
shippingInfo: [
{
shippingServiceCost: [
{
@currencyId: "USD",
__value__: "24.0"
}
],
shippingType: [
"Flat"
],
shipToLocations: [
"US"
],
expeditedShipping: [
"false"
],
oneDayShippingAvailable: [
"false"
],
handlingTime: [
"1"
]
}
],
sellingStatus: [
{
currentPrice: [
{
@currencyId: "USD",
__value__: "61.99"
}
],
convertedCurrentPrice: [
{
@currencyId: "USD",
__value__: "61.99"
}
],
bidCount: [
"9"
],
sellingState: [
"Active"
],
timeLeft: [
"P0DT0H8M7S"
]
}
],
listingInfo: [
{
bestOfferEnabled: [
"false"
],
buyItNowAvailable: [
"false"
],
startTime: [
"2012-08-17T21:50:15.000Z"
],
endTime: [
"2012-08-20T21:50:15.000Z"
],
listingType: [
"Auction"
],
gift: [
"false"
]
}
],
returnsAccepted: [
"true"
],
condition: [
{
conditionId: [
"3000"
],
conditionDisplayName: [
"Used"
]
}
],
isMultiVariationListing: [
"false"
]
}
]
}
],
paginationOutput: [
{
pageNumber: [
"1"
],
entriesPerPage: [
"2"
],
totalPages: [
"486815"
],
totalEntries: [
"973629"
]
}
],
itemSearchURL: [
"http://www.ebay.com/sch/i.html?_nkw=laptops&_ddo=1&_ipg=2&_pgn=1"
]
}
]
}

我尝试使用以下 for 循环获取“项目”数据:

  data = json.load(urllib2.urlopen(url))
#print data
for item in data['findItemsByKeywordsResponse'][0]['searchResult'][0]['item']:
for itemId in item['itemId']:
print itemId

这工作正常,但我不确定如何实际获取我试图在底部显示的所有项目数据。

[
{
@count: "2",
item: [
{},
{}
]
}
],

最佳答案

data['findItemsByKeywordsResponse'] 是一个 list,因此您可以使用 the_list[0] 访问其中的项目,依此类推.

list 中没有键,键属于dict

关于Python从urllib请求中解析json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12045719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com