0
樣本數據庫:獲取JSON信息在Python
"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
}
我想打印所有城市名稱。我的代碼是:
Jdata = json.loads(self.data)
for i in Jdata["metros"]:
print Jdata["name"]
但是當我運行此我得到「KeyError異常:‘名’」
什麼是正確的語法來獲得城市的名字嗎?
謝謝,它的工作原理! – Chris 2014-10-03 05:35:17