[英]Access JSON to DICT in Python
I have the next JSON in JS我在 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
}]
};
and I did parsed_input = json.loads(self.intervalos)
我做了parsed_input = json.loads(self.intervalos)
but now I don't know how to access to my dict.但现在我不知道如何访问我的字典。 I tried with我试过
intervalos[operandos][extremoInferior])
but it returns an error.但它返回一个错误。
Could you help me for accessing to any element of my dict?你能帮我访问我的字典的任何元素吗?
After deserializing JSON to Python object you could simply access to elements.将 JSON 反序列化为 Python 对象后,您可以简单地访问元素。 For example:例如:
parsed_input = json.loads(self.intervalos)
extremo_inferior_0 = parsed_input['operandos'][0]['extremoInferior']
Please try this code:请试试这个代码:
import simplejson as json
json_string = """{"operandos":[
{
"extremoInferior":"somevalue1",
"extremoSuperior":"somevalue2"
},
{
"extremoInferior":"somevalue3",
"extremoSuperior":"somevalue4"
}]
}"""
json_data = json.loads(json_string)
print "Complete Dict: "
print json_data
print "operandos -> extremoInferior: "
print json_data['operandos'][0]['extremoInferior']
intervalos['operandos'][0]['extremoInferior']
or或者
intervalos['operandos'][1]['extremoInferior']
intervalos['operandos']
is defined as an array of two of these objects. intervalos['operandos']
被定义为这些对象中的两个的数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.