Sample of the database:
"metros" : [
{
"code" : "SCL" ,
"name" : "Santiago" ,
"country" : "CL" ,
"continent" : "South America" ,
"timezone" : -4 ,
"coordinates" : {"S" : 33, "W" : 71} ,
"population" : 6000000 ,
"region" : 1
} , {
"code" : "LIM" ,
"name" : "Lima" ,
"country" : "PE" ,
"continent" : "South America" ,
"timezone" : -5 ,
"coordinates" : {"S" : 12, "W" : 77} ,
"population" : 9050000 ,
"region" : 1
}
I'm trying to print all city names. My code is:
Jdata = json.loads(self.data)
for i in Jdata["metros"]:
print Jdata["name"]
But when I run this I'm getting "KeyError: 'name'"
What's the correct syntax to get the name of the cities?