回答編集履歴
1
d
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
`Resources/*/PolicyDocument/Properties/PolicyDocument/Statement/0/Action` にアクセスしたい場合は、json['Resources'] に
|
1
|
+
`Resources/*/PolicyDocument/Properties/PolicyDocument/Statement/0/Action` にアクセスしたい場合は、json['Resources'] 配下の任意の要素にアクセスするには、values() 関数で for ループすればよいです。
|
2
2
|
|
3
3
|
```python
|
4
4
|
import json
|
@@ -6,7 +6,7 @@
|
|
6
6
|
with open("test.json") as f:
|
7
7
|
data = json.load(f)
|
8
8
|
|
9
|
-
for
|
9
|
+
for val in data["Resources"].values():
|
10
10
|
print(val["Properties"]["PolicyDocument"]["Statement"][0]["Action"])
|
11
11
|
```
|
12
12
|
|
@@ -15,7 +15,7 @@
|
|
15
15
|
cloudformation:*
|
16
16
|
```
|
17
17
|
|
18
|
-
|
18
|
+
values() 関数の使い方は dict と同じです。
|
19
19
|
|
20
20
|
```python
|
21
21
|
import json
|
@@ -28,8 +28,8 @@
|
|
28
28
|
"""
|
29
29
|
|
30
30
|
data = json.loads(j)
|
31
|
-
for
|
31
|
+
for val in data.values():
|
32
|
-
print(
|
32
|
+
print(val)
|
33
|
-
#
|
33
|
+
# red
|
34
|
-
#
|
34
|
+
# #f00
|
35
35
|
```
|