leui
leui

Reputation: 23

JSON Extraction in Python.

Trying to get specific data through my JSON format and I'm unable to do so. Trying to do it in Python and I want more than 1 thing printed out. Im providing a example code to make it clear. The name of the file is blah

{ u'info': { u'more_info': { u'xyz': u'[]',
                           u'xyz': None,
                           u'xyz': 00000,
                           u'description': u'blah blah blah',
                           u'xyz': 0000,
                           u'url':
                           u'xyz': False,
                           u'name': u'BLAH BLAH',
                           u'xyz': 10,
                           u'xyz': 1,

I refer to the documentation, but that still fails me.

I tried this

for xyz in blah['info']['more_info']:
fs = xyz['name']['description']['url'] 

The error is that: "TypeError: String indices must be integer"

Please help.

Upvotes: 2

Views: 52

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798436

Iterating over a dict yields keys. But since you have a dict, just access the items directly.

print blah[u'info'][u'more_info'][u'name']
print blah[u'info'][u'more_info'][u'description']
print blah[u'info'][u'more_info'][u'url']

Upvotes: 1

Related Questions