python - JSON.LOADS is picking only 2 resultset -


i trying use json search through googlemapapi. so, give location "plymouth" - in googlemapapi showing 6 resultset when try parse in json, getting length of 2. tried multiple cities too, getting resultset of 2 rather. wrong below?

import urllib.request ur import urllib.parse urp import json  url = "http://maps.googleapis.com/maps/api/geocode/json?address=plymouth&sensor=false" uh = ur.urlopen(url) data = uh.read() count = 0  js1 = json.loads(data.decode('utf-8') ) print ("length: ", len(js1)) result in js1:     location = js1["results"][count]["formatted_address"]     lat = js1["results"][count]["geometry"]["location"]["lat"]     lng = js1["results"][count]["geometry"]["location"]["lng"]     count = count + 1      print ('lat',lat,'lng',lng)     print (location) 

simply replace for result in js1: for result in js1['results']:


by way, posted in comment in question, no need use counter. can rewrite for loop as:

for result in js1['results']:     location = result["formatted_address"]     lat = result["geometry"]["location"]["lat"]     lng = result["geometry"]["location"]["lng"]      print('lat',lat,'lng',lng)     print(location) 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -