用Python解析来自Supreme网站的Json时出现问题
首先,这是我的代码:用Python解析来自Supreme网站的Json时出现问题,python,json,parsing,Python,Json,Parsing,首先,这是我的代码: import urllib.request, json with urllib.request.urlopen("https://www.supremenewyork.com/mobile_stock.json") as url: data = json.loads(url.read().decode()) print(type(data['Shoes'])) 我试图解析Json,这是我用Python从Supreme网站上得到的。我正在尝
import urllib.request, json
with urllib.request.urlopen("https://www.supremenewyork.com/mobile_stock.json") as url:
data = json.loads(url.read().decode())
print(type(data['Shoes']))
我试图解析Json,这是我用Python从Supreme网站上得到的。我正在尝试过滤掉“Shoes”数组。打印出整个“数据”是可行的,但是如果我试图过滤掉“Shoes”数组,我会得到以下错误:
Traceback (most recent call last):
File "C:\Users\-\PycharmProjects\-\test.py", line 7, in <module>
print(type(data['Shoes']))
KeyError: 'Shoes'
如果您查看json,鞋属于产品和类别:
data["products_and_categories"]["Shoes"]
这将为您提供所需的数据如果您查看json,鞋位于产品和类别下:
data["products_and_categories"]["Shoes"]
print(data['products_and_categories']['Shoes'])
这将为您提供所需的数据谢谢!成功了@为乐趣编程请接受并投票回答(如果有帮助):)是否这样做:)快速问题,我如何访问例如在“Shoes”数组中的“name”?仅仅添加['name']似乎不起作用。ah发现了方法:数据['products_and_categories][“Shoes”][0]['name']哦,对不起,我以为我可以给你们两个,我更正了:)谢谢!成功了@为乐趣编程请接受并投票回答(如果有帮助):)是否这样做:)快速问题,我如何访问例如在“Shoes”数组中的“name”?仅仅添加['name']似乎不起作用。啊发现了方法:数据['products_and_categories][“Shoes”][0]['name']哦,对不起,我以为我可以给你们两个,我更正了:)也感谢你们!也谢谢你!
print(data['products_and_categories']['Shoes'])