我試圖分析在Python中的一些數據我有一些JSON:解析JSON數組到對象中?
{
"data sources": [
"http://www.gcmap.com/"
],
"metros": [
{
"code": "SCL",
"continent": "South America",
"coordinates": {
"S": 33,
"W": 71
},
"country": "CL",
"name": "Santiago",
"population": 6000000,
"region": 1,
"timezone": -4
},
{
"code": "LIM",
"continent": "South America",
"coordinates": {
"S": 12,
"W": 77
},
"country": "PE",
"name": "Lima",
"population": 9050000,
"region": 1,
"timezone": -5
}
]
}
如果我想解析「地鐵」數組和數組Python類Metro
的對象,我將如何設置類?
我在想:
class Metro(object):
def __init__(self):
self.code = 0
self.name = ""
self.country = ""
self.continent = ""
self.timezone = ""
self.coordinates = []
self.population = 0
self.region = ""
所以,我想通過每一個地鐵站和把數據轉換成相應的Metro
對象和地點對象爲對象的Python的數組...我怎麼能遍歷JSON地鐵?
我不明白的問題。當你有JSON的時候你有一個對象,你可以從這個對象獲得地鐵列表 – voscausa 2013-02-21 19:20:16