【发布时间】:2021-01-28 16:02:11
【问题描述】:
我对python很陌生,所以也许我的问题有一个简单的答案。 我已从 json 文件中导入数据,如下所示:
input:
with open('file_destination.json', 'r', encoding='utf-8') as f:
data = json.load(f)
print(data)
output:
[{'Node': {'Construction': {'id': 'd9794e40-c894-5027-8576-b30a3eb3c95c'}]
我希望能够提取数据,例如id = d9794e40-c894-5027-8576-b30a3eb3c95c,但是我得到:
Traceback (most recent call last):
File "main.py", line 11, in <module>
print(data['id'])
TypeError: list indices must be integers or slices, not str
谁能帮我解决这个问题?
【问题讨论】:
标签: typeerror