这是我的json数据:
{
"AccountRegion": "testaccount",
"AssumeRole": "arn",
"Policies": [
"hello",
"world"
],
"Region": "usa"
},
{
"AccountRegion": "testaccount-2",
"AssumeRole": "arn",
"Policies": "anotherpolicy",
"Region": "usa"
}
我无法弄清楚如何遍历JSON。我想遍历数据并获取数据集中每个成员的策略。我怎么能做到这一点?
答案 0 :(得分:0)
试试这个。
arr = [{
"AccountRegion": "testaccount",
"AssumeRole": "arn",
"Policies": [
"hello",
"world"
],
"Region": "usa"
},
{
"AccountRegion": "testaccount-2",
"AssumeRole": "arn",
"Policies": "anotherpolicy",
"Region": "usa"
}]
for x in range(0,len(arr)):
print arr[x]['AccountRegion']
答案 1 :(得分:0)
你可以试试这个
import json
parsedJson = json.loads(data)
for i in parsedJson:
print parsedJson["Policies"]