Python 如何访问request.get().json()响应中的深度嵌套键?

Python 如何访问request.get().json()响应中的深度嵌套键?,python,Python,我试图请求这个产品的项目可用性,我已经设法请求了Json字符串,这允许我查看项目可用性,但我想解析Json字符串的其余部分,除了字符串的某一部分。我对python还很陌生,但到目前为止我得到的是 #Load Vars -- Note the Headers Wont Be Static I have to change them with a lib headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64

我试图请求这个产品的项目可用性,我已经设法请求了Json字符串,这允许我查看项目可用性,但我想解析Json字符串的其余部分,除了字符串的某一部分。我对python还很陌生,但到目前为止我得到的是

    #Load Vars -- Note the Headers Wont Be Static I have to change them with a lib
headers = {
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0',
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  'Accept-Language': 'en-US,en;q=0.5',
  'Upgrade-Insecure-Requests': '1',
  'Connection': 'keep-alive',
}

url = ('https://target.com')
#Ping the site to see if its up and we arent blocked 200 means good 400 means bad LOL 

response = requests.get( url, headers=headers)

print(response)

#Load Product XHR URL

xhrURL = ("https://redsky.target.com/redsky_aggregations/v1/web/pdp_fulfillment_v1?key=ff457966e64d5e877fdbad070f276d18ecec4a01&tcin=81114595&store_id=1843&store_positions_store_id=1843&has_store_positions_store_id=true&zip=92506&state=CA&latitude=33.959917&longitude=-117.405621&scheduled_delivery_store_id=291&pricing_store_id=1843")

jsonData = requests.get(xhrURL).json()

print(jsonData)
它带着

    {'data': {'product': {'__typename': 'Product', 'tcin': '81114595', 'notify_me_enabled': False, 'store_positions': [{'aisle': 41, 'block': 'E'}, {'aisle': 40, 'block': 'E'}], 'fulfillment': {'product_id': '81114595', 'is_out_of_stock_in_all_store_locations': True, 'store_options': [{'location_name': 'Riverside SE', 'location_address': '2755 Canyon Springs Pkwy,Riverside,CA,92507-0932', 'location_id': '1843', 'search_response_store_type': 'PRIMARY', 'location_available_to_promise_quantity': 0.0, 'order_pickup': {'availability_status': 'OUT_OF_STOCK', 'reason_code': 'OUT_OF_STOCK'}, 'in_store_only': {'availability_status': 'OUT_OF_STOCK'}, 'ship_to_store': {'availability_status': 'UNAVAILABLE'}}], 'shipping_options': {'availability_status': 'OUT_OF_STOCK', 'loyalty_availability_status': 'OUT_OF_STOCK', 'available_to_promise_quantity': 0.0, 'reason_code': 'INVENTORY_UNAVAILABLE', 'minimum_order_quantity': 1.0, 'services': []}, 'scheduled_delivery': {'availability_status': 'UNAVAILABLE'}}}}}
这很好,但我想进一步分析它,只打印“可用状态”

如有任何意见,我们将不胜感激


最佳-armando

通过这种方式,您可以访问
jsonData

print(jsonData['data']['product']['fulfillment']['shipping_options']['availability_status'])

requests.get(xhrURL).json()
返回json的python表示形式:对象将是一个字典、数组、列表等,您只需使用正确的键访问值。它是一个字典-您可以像访问任何其他字典一样访问其数据。在您显示的数据中,至少有5个键是
'availability\u status'
,返回的可能不止1个shop\u选项(这是一个列表,因此可能有多个shop。不清楚您想要5个
'availability\u status'
中的哪一个。此外,您可能需要检查
json\u数据[“data”[“product”][“fulfillment”][“是否所有门店都缺货”]
如果根本不可用,请快速查看响应中至少有5个
“可用性状态”
键-也可能在门店选项中返回多个门店