我有一个 json 文件,我正在使用json库读取该文件
这是json内容(示例)
{
"type": "champion",
"format": "standAloneComplex",
"version": "10.18.1",
"data": {
"Aatrox": {
"version": "10.18.1",
"id": "Aatrox",
"key": "266",
"name": "Aatrox"
},
"Ahri": {
"version": "10.18.1",
"id": "Ahri",
"key": "103",
"name": "Ahri",
},
}
现在我如何检查是否key等于 266 并返回 的值name?
我正在尝试这样的事情
import json
with open('./source/champion.json') as json_file:
data_champs = json.load(json_file)['data']
for champ in data_champs:
for champ_info in data_champs[champ]:
if champ['key'] == 266:
print(champ)
但返回 TypeError: 字符串索引必须是整数
精慕HU
qq_遁去的一_1
猛跑小猪
相关分类