pythonでjsonの配列にアクセスする時のメモ
jsonファイル
test.json
{
"section1":{
"key":"key1",
"number": [
["a", "b"],
["c", "d"],
["e", "f"]
]
},
"section2":{
"key":"key2",
"number": 2
}
}
pythonファイル
test.py
import json
json_open = open('test.json', 'r')
json_load = json.load(json_open)
print(json_load)
print(json_load["section1"]["number"][0])
print(json_load["section1"]["number"][1])
print(json_load["section1"]["number"][2])
print(json_load["section1"]["number"][0][0])
print(json_load["section1"]["number"][0][1])
実行
$ python test.py
{'section1': {'key': 'key1', 'number': [['a', 'b'], ['c', 'd'], ['e', 'f']]}, 'section2': {'key': 'key2', 'number': 2}}
['a', 'b']
['c', 'd']
['e', 'f']
a
b