Wednesday 15 June 2011

JSON parsing using python -



JSON parsing using python -

i'm attempting understand basics of json , thought using google translate examples interesting. i'm not making requests via api have next illustration have saved "file.json":

{ "data": { "detections": [ [ { "language": "en", "isreliable": false, "confidence": 0.18397073 } ] ] } }

i'm reading in file , used simplejson:

json_data = open('file.json').read() json = simplejson.loads(json_data) >>> json {'data': {'detections': [[{'isreliable': false, 'confidence': 0.18397073, 'language': 'en'}]]}}

i've tried multiple ways print value of 'language' no success. example, fails. pointers appreciated!

print json['detections']['language']

you need json['data']['detections'][0][0]['language']. illustration info shows, 'language' key of dict within list within list within 'detections' dict within 'data' dict.

python json

No comments:

Post a Comment