[{"Attachment": [
{
"Page:": [
{
"Path": "a\\b\\c.pdf", #field to be extracted
"PageID": 1
}
]
}
],
"ID": 13221}]
我尝试了以下操作,但遇到TypeError:列表索引必须是整数,而不是str
with open(file) as f:
d = json.load(f)
print(d[0]['Attachment']['Page']['Path'])
答案 0 :(得分:2)
d[0]['Attachment']
是一个列表,d[0]['Attachment'][0]['Page:']
也是如此。
with open(file) as f:
d = json.load(f)
print(d[0]['Attachment'][0]['Page:'][0]['Path'])
会做。