【发布时间】:2020-11-21 12:17:04
【问题描述】:
我有这个 json 文件
https://pastebin.com/embed_js/PknXEGq2
这是我目前的代码
import json
data = json.load(open('data.json'))
Product = []
Products = []
def get_products():
query_one = data['Bundles']
for first in query_one:
Product = first.get('Product') or []
for i in Product:
for key, val in i.items():
if key == None :
print(i.index(key) + key)
elif key is False:
print("Error")
else:
print("You can buy " + str(key) + " at our store at " + str(val))
Products = data['Bundles']
var_two = Products
for second in Products:
var_two = second.get('Products')
for j in var_two:
for key_two, val_two in j.items():
if key_two == None:
print(j.index(key_two) + key_two)
elif key_two is False:
print("Error")
else:
print("You can buy " + str(key_two) + " at our store at " + str(val_two))
return ""
get_products()
问题是我无法为某些获取正确的值和键,所以我如何指定要从 json 文件中获取的正确元素(产品名称和价格)
结果必须是
您可以在 12 点在我们的商店购买 Tommee Tippee Ctn 过渡杯
【问题讨论】:
-
你能添加一个你需要的实际输出的例子吗?
-
您可以在我们的商店购买 Tommee Tippee Ctn 过渡杯 12