简体   繁体   English

我无法从 python 中的 JSON 数据中找到属性值

[英]I am unable to find attribute values from JSON data in python

I want to find id and options in this JSON data.我想在这个 JSON 数据中找到idoptions 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 &euro;\n\n\n    </span>\n</span>\n\n</div>\n\n"
    },
    "longDescription": "<ul>\n\t<li>STYLE:&nbsp;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.

相关问题 我无法在 python 的数据框中删除特定值 - I am unable to drop specific values in a data frame in python 我有一个json格式的数据文件。 如何找到并打印前 20 个 eij_max 值和相关的 Pretty_formula? 我正在使用蟒蛇 - I have a data file in json format. How can I find and print the top 20 eij_max values and the associated pretty_formula? I am using python 使用python中的请求函数解析json数据...我无法访问对象 - parsing json data using request function in python… i am unable to access the objects 我无法从 json 文件中调用 json - I am unable to call the json from the json file 为什么我无法使用 selenium python 从 Highchart 的隐藏工具提示中抓取值? - Why am I unable to scrape values from a Hidden tooltip of a Highchart using selenium python? 为什么我无法使用 Python 和 Selenium 找到 html 元素? - Why am I unable to find html element with Python and Selenium? 我正在学习如何通过重要性采样来拟合 python 上的数据,我正在尝试对 x 和 y 值进行采样并找到它们的权重,但我遇到了错误 - I am learning how to data fit on python with importance sampling, I am trying to sample x and y values and find their weights but I am getting errors 无法使用 python 从 json 中提取数据 - Unable to extract data from json using python 无法从JQUERY向python发送JSON数据 - Unable to send JSON data to python from JQUERY 无法从python中的JSON响应解析数据 - Unable to Parse the data from JSON response in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM