[英]I am unable to find attribute values from JSON data in python
I want to find id
and options
in this JSON data.我想在这个 JSON 数据中找到
id
和options
。 Here's What I did so far.这是我到目前为止所做的。
data = """
"list": null,
"promotionID": "",
"isFreeShippingApplicable": true,
"html": "\n\n\n<div class=\"b-product-tile-price\">\n \n \n\n\n\n<span class=\"b-product-tile-price-outer\">\n <span class=\"b-product-tile-price-item\">\n 1200 €\n\n\n </span>\n</span>\n\n</div>\n\n"
},
"longDescription": "<ul>\n\t<li>STYLE: BQ4420-100</li>\n\t<li>Laufsohle: Gummi</li>\n\t<li>Obermaterial: beschichtetes Leder, Textil</li>\n\t<li>Innenmaterial: Textil</li>\n</ul>\n",
"shortDescription": null,
"availability": {
"messages": [
"Sofort lieferbar"
],
"inStockDate": null,
"custom": {
"code": null,
"label": null,
"orderable": true,
"sizeSelectable": true,
"badge": false
"""
find_values = json.loads(data)
id = find_values["id"]
variables = find_product_data["variables"]
print(id, variables)
The output is an erro but when I try to get the values of first the attribute action
, it gets returned but not the others. output 是一个错误,但是当我尝试获取第一个属性
action
的值时,它会被返回,而不是其他的。
You can't access the id
directly, because it is nested inside another dictionary.您不能直接访问
id
,因为它嵌套在另一个字典中。 What you have to do is get that dict first and then access the id
.您要做的是先获取该 dict 然后访问
id
。
find_values = json.loads(data)
product = find_values["product"]
id_value = product("id")
If you are working with an IDE it could help to debug your code and see how the dict is actually nested.如果您使用的是 IDE,它可能有助于调试您的代码并查看 dict 的实际嵌套方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.