天天看點

python循環周遊json_如何在Python中循環JSON

我不知道如何周遊一個深度超過1層的JSON對象。目标是:{

"data":[

{

"id":"251228454889939/insights/page_fan_adds_unique/day",

"name":"page_fan_adds_unique",

"period":"day",

"values":[

{

"value":9,

"end_time":"2012-05-29T07:00:00+0000"

},

{

"value":5,

"end_time":"2012-05-30T07:00:00+0000"

}

],

"title":"Daily New Likes",

"description":"Daily The number of new people who have liked your Page (Unique Users)"

},

{

"id":"251228454889939/insights/page_fan_adds/day",

"name":"page_fan_adds",

"period":"day",

"values":[

{

"value":9,

"end_time":"2012-05-29T07:00:00+0000"

},

{

"value":5,

"end_time":"2012-05-30T07:00:00+0000"

}

],

"title":"Daily New Likes",

"description":"Daily The number of new people who have liked your Page (Total Count)"

}

]

}

代碼:def parseJsonData(data):

output_json = json.loads(data)

for i in output_json:

print i

for k in output_json[i]:

print k

為什麼我不能通路像:output_json[data][id]這樣的對象?

如果我嘗試以下操作,就會出錯:string indice must be an integer