2

I have the next JSON in JS

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)

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?

2
  • after you parse your data, you assign it to parsed_input. So you have to use that variable to retrieve your data. Rest is dictionary and list operation. Commented Jun 15, 2015 at 8:35
  • The keys to the dictionary are strings. Use them. Commented Jun 15, 2015 at 8:36

3 Answers 3

2

After deserializing JSON to Python object you could simply access to elements. For example:

parsed_input = json.loads(self.intervalos)
extremo_inferior_0 = parsed_input['operandos'][0]['extremoInferior']
Sign up to request clarification or add additional context in comments.

Comments

2

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']

Comments

-2
intervalos['operandos'][0]['extremoInferior']

or

intervalos['operandos'][1]['extremoInferior']

intervalos['operandos'] is defined as an array of two of these objects.

2 Comments

You can not get values form intervalos since it is not a python object!
Yes, you are right - I just wanted to indicate that he forgot the "Array" level in his original question. (intervalos[operandos][extremoInferior])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.