这就是我的JSON的样子:
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "xxx",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::xxx"
},
{
"Sid": "yyy",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::xxx/AWSLogs/yyy/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
}]
}
我想循环通过Statement数组。这就是我的循环的样子:
for p in policy['Statement']:
print p
这是我得到的错误:
TypeError: string indices must be integers
print(type(policy))
收益<type 'unicode'>
这就是政策的样子:
{
u'Policy': u'{
"Version": "2012-10-17",
"Statement": [{
"Sid": "xxx",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::xxx"
},
{
"Sid": "yyy",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::yyy/AWSLogs/yyy/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
}]
}'
}