Iterating json response from google api using python -


i took nearby location google api , json, when try split json receive error

{     u'status':u'ok',   u'next_page_token':u'coqc9aaaahepdlfivauuqz6y6wwaskbmq5aaoyr0bbu97upcmy4ei1ea5t-6s6iobzdz5_rib7ywocdg-lf9ian5jrutqvgl7mwbba_un3efs7xzjmlvx-iksauieio-wu3r25zk9sl3yc5d_vdgvn3vqjka7bbidwhkloj4rfngjbsgvwvqonj5glrbwvvrw9nu6dni70c2wdqqy_65b_jfjjijytawrlfoyl7ggpxk5gng7qgsfdttjii9zdfkxcj3osuzklretjradtgfaqgxr0ka_h5btbuxz3ut6r-dyqdj2qd1tr_0oavfkgb9t0qfbuyse7bdeteawddv7msmmxeyhqusemcbruhu5pb8x4eopbpw9ncaflgqttickqygyy-boaj1_3x3saet',   u'html_attributions':[     u'listings <a href="http://www.indiacom.com/">indiacom yellow pages</a>'],   u'results':[     {        u'name':u'institute financial management , research',      u'reference':u'cpqbgwaaal5gg4t18lzupntezvkweah0jlbutyc_rmxoycl3kndgq05wvkovvhiiyhnnqeoxcx1tcwesii0vsvwugaskyy2unj_brtd5zblxzd7nlxp9l-foqletrgbpa6dlnzhm6nmcu3jtjibaoymqjomgl9cot7c4y18o_3e1cjrzpjfg5hk6trq2u2lvjnd2zxj6ixiqc2iuhwqilkrbtud3ke5gdbou1szlopy-_karc7leoq2nakhtwsk',      u'geometry':{           u'location':{              u'lat':13.062882,            u'lng':80.238669         }      },      u'place_id':u'chijkze7o2zmujorlactnpjba3u',      u'vicinity':u'24,      kothari road,      nungambakkam,      chennai',      u'photos':[           {              u'photo_reference':u'cnroaaaaph-yjpjfjpyltzyhyts_tivfa7vve-lmii8xbuydzjlmxbzdnkxucugck9w-nfjgurj-jorqjlruurgvt1oz94osennc8bzglbi4joj1w-dqsyiwqqzqddna-u0trkj_8s91ff3uerww341951yb2hiqx7gfjin5twkkecgwerj9obou0cdkrd6b2pl3bcp09hcyvleefaq',            u'width':816,            u'html_attributions':[                 u'from google user'            ],            u'height':459         }      ],      u'scope':u'google',      u'id':u'2e9a63cf7368e0f90e2a20711ac56853b7c34462',      u'types':[           u'school',         u'establishment'      ],      u'icon':         u'http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png'   },   {        u'rating':4.2,      u'name':u'sri sankara senior secondary school',      u'reference':u'coqbdgaaaj-uc78ebpnlx6adzhezmwrs9soj9vwtqsqzolqza-r3qozdurl4xxwprdhd9k_bvp0t_fhewqt4w42x0z01uqr7dtq5cz7ioa9zbviqpwoksqhxjbjqjx05yxvqgpb9mcfeikhpfkskiaz5mprldgklbhq8cld4fm9biwnme_mjehd35r4ggbvnu4j-x0lfaw3bghrpqexerzf3jjjklbhs2hwvrvp2xg',      u'geometry':{           u'location':{              u'lat':13.009931,            u'lng':80.260746         }      },      u'place_id':u'chijh_fxcelnujord4vkdqfy_dm',      u'vicinity':u'9/21 vasantha press road,      vasanta press road,      adyar,      landmarks malar hospital/theosophical society,      chennai',      u'photos':[           {              u'photo_reference':u'cnrwaaaairfqsujn7jb5_ggdfepbldhptkmarqhv-6hr5fut-mjb6sco7zyz1jamqogvtqxlbezzjxc67bvollbhtiriqwkybxoi9dhlebmrcgmtrorjedkvidy_8zc0pofzozggh2xdflrh1irswzuea0ijfriqaatxa2bymp1ked4vxnzfnxoutwd5y-4-8zpnprhukofuvsztcoq',            u'width':297,            u'html_attributions':[               ],            u'height':297         }      ],      u'scope':u'google',      u'id':u'a8dc412bac3ea790260d2c7d6fe08271ae883a4e',      u'types':[           u'school',         u'establishment'      ],      u'icon':         u'http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png'   },   {        u'rating':4.5,      u'name':u'chettinad vidyashram',      u'reference':u'cnroaaaabig1-6ectuocqw5hcenhtbhlamp-nfdw_w1vev94fxviyczhhsqmn95vetkcgbleme6qd30ughxmlxfwxitcls-slc7fgxwgl2jincltjb1rypyc--gr6hs-9ct7xq2f46-daqnpf5n2sra1cnjjsbiqvvldztqmh2bmqkjer9mlzxou3gbs1tpgvj8h5uo71qkttyj1cdq',      u'geometry':{           u'location':{              u'lat':13.017083,            u'lng':80.269503         }      },      u'place_id':u'chijr3w9sdxnujors2vfnh-erna',      u'vicinity':u'rajah annamalaipuram,      chennai',      u'photos':[           {              u'photo_reference':u'cnroaaaaeuhwpdko87eegp7fzm7ake3vcqd6gfebbjo2fhyrhdullzw-xdepstzetly74id6nmof5lqm4bhz56c1crnsxmdqaxj-rcjr2cpq2vfjaixzmbg3c-0ttnmmupugsjkaldr6rwcwddvmg8fanwhgyriqxypx89xda5fl7e5ruecrwhou-sexdqur-grayvlkb8iq_1mf-r8',            u'width':968,            u'html_attributions':[                 u'from google user'            ],            u'height':968         }      ],      u'scope':u'google',      u'id':u'f3b774d4c11a4bd20585669d9c4ae57fc12e5652',      u'types':[           u'school',         u'establishment'      ],      u'icon':         u'http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png'   }, 

here python code

res = json.dumps(response)   result in response[status][results]:     print result['status'] 

as json big put half json data only. error ror @ 1431:global name 'status' not defined

how split json

when print type(response)

type tuple

if json string want load native structure loads , iterate on native structure. looking @ json string have seems if individual results don't have status field. this:

res = json.loads(response) print res['status'] result in res['results']:     print result 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -