gpt4 book ai didi

python - 在 Python 中访问 JSON 到 DICT

转载 作者:太空宇宙 更新时间:2023-11-04 03:31:52 25 4
gpt4 key购买 nike

我在 JS 中有下一个 JSON

var intervalos= {
"operandos":[{
"extremoInferior":$(edit_numvar).context.value,
"extremoSuperior":$(edit_numvar2).context.value
},
{
"extremoInferior":$(edit_numvar3).context.value,
"extremoSuperior":$(edit_numvar4).context.value
}]
};

我做了 parsed_input = json.loads(self.intervalos)

但现在我不知道如何访问我的字典。我试过

intervalos[operandos][extremoInferior])     

但它返回一个错误。

你能帮我访问我的字典中的任何元素吗?

最佳答案

将 JSON 反序列化为 Python 对象后,您可以简单地访问元素。例如:

parsed_input = json.loads(self.intervalos)
extremo_inferior_0 = parsed_input['operandos'][0]['extremoInferior']

关于python - 在 Python 中访问 JSON 到 DICT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30840399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com