我尝试了不同的 for 循环尝试迭代这个 JSON,但我不知道如何做到这一点。我有一个数字列表,想要将其与每个“数据”对象下的“键”值(例如,Aatrox、Ahri、Akali 等)进行比较,如果数字匹配,则存储“名称”
另一个列表中的值。
例子:
数字列表 = [266, 166, 123, 283]
266 和 166 将分别匹配 Aatrox 和 Akshan 对象中的“密钥”,因此我想提取该名称并将其存储在列表中。
我知道这个 JSON 主要是通过键值访问而不是被索引,所以我不确定如何迭代 for 循环中的所有“数据”对象。
JSON 我参考:
{
"type": "champion",
"format": "standAloneComplex",
"version": "12.2.1",
"data": {
"Aatrox": {
"version": "12.2.1",
"id": "Aatrox",
"key": "266",
"name": "Aatrox",
"title": "the Darkin Blade",
"blurb": "Once honored defenders of Shurima against the Void, Aatrox and his brethren would eventually become an even greater threat to Runeterra, and were defeated only by cunning mortal sorcery. But after centuries of imprisonment, Aatrox was the first to find...",
"info": {
"attack": 8,
"defense": 4,
"magic": 3,
"difficulty": 4
},
"image": {
"full": "Aatrox.png",
"sprite": "champion0.png",
"group": "champion",
"x": 0,
"y": 0,
"w": 48,
"h": 48
},
"tags": [
"Fighter",
"Tank"
],
"partype": "Blood Well",
"stats": {
"hp": 580,
"hpperlevel": 90,
"mp": 0,
"mpperlevel": 0,
"movespeed": 345,
"armor": 38,
"armorperlevel": 3.25,
"spellblock": 32,
"spellblockperlevel": 1.25,
"attackrange": 175,
"hpregen": 3,
"hpregenperlevel": 1,
"mpregen": 0,
"mpregenperlevel": 0,
"crit": 0,
"critperlevel": 0,
"attackdamage": 60,
"attackdamageperlevel": 5,
"attackspeedperlevel": 2.5,
"attackspeed": 0.651
}
},
"Ahri": {
"version": "12.2.1",
"id": "Ahri",
"key": "103",
"name": "Ahri",
"title": "the Nine-Tailed Fox",
"blurb": "Innately connected to the latent power of Runeterra, Ahri is a vastaya who can reshape magic into orbs of raw energy. She revels in toying with her prey by manipulating their emotions before devouring their life essence. Despite her predatory nature...",
"info": {
"attack": 3,
"defense": 4,
"magic": 8,
"difficulty": 5
},
"image": {
"full": "Ahri.png",
"sprite": "champion0.png",
"group": "champion",
"x": 48,
"y": 0,
"w": 48,
"h": 48
},
"tags": [
"Mage",
"Assassin"
],
"partype": "Mana",
"stats": {
"hp": 526,
"hpperlevel": 92,
"mp": 418,
"mpperlevel": 25,
"movespeed": 330,
"armor": 21,
"armorperlevel": 3.5,
"spellblock": 30,
"spellblockperlevel": 0.5,
"attackrange": 550,
"hpregen": 5.5,
"hpregenperlevel": 0.6,
"mpregen": 8,
"mpregenperlevel": 0.8,
"crit": 0,
"critperlevel": 0,
"attackdamage": 53,
"attackdamageperlevel": 3,
"attackspeedperlevel": 2,
"attackspeed": 0.668
}
},
"Akali": {
"version": "12.2.1",
"id": "Akali",
"key": "84",
"name": "Akali",
"title": "the Rogue Assassin",
"blurb": "Abandoning the Kinkou Order and her title of the Fist of Shadow, Akali now strikes alone, ready to be the deadly weapon her people need. Though she holds onto all she learned from her master Shen, she has pledged to defend Ionia from its enemies, one...",
"info": {
"attack": 5,
"defense": 3,
"magic": 8,
"difficulty": 7
},
"image": {
"full": "Akali.png",
"sprite": "champion0.png",
"group": "champion",
"x": 96,
"y": 0,
"w": 48,
"h": 48
},
"tags": [
"Assassin"
],
"partype": "Energy",
"stats": {
"hp": 500,
"hpperlevel": 105,
"mp": 200,
"mpperlevel": 0,
"movespeed": 345,
"armor": 23,
"armorperlevel": 3.5,
"spellblock": 37,
"spellblockperlevel": 1.25,
"attackrange": 125,
"hpregen": 9,
"hpregenperlevel": 0.9,
"mpregen": 50,
"mpregenperlevel": 0,
"crit": 0,
"critperlevel": 0,
"attackdamage": 62,
"attackdamageperlevel": 3.3,
"attackspeedperlevel": 3.2,
"attackspeed": 0.625
}
},
"Akshan": {
"version": "12.2.1",
"id": "Akshan",
"key": "166",
"name": "Akshan",
"title": "the Rogue Sentinel",
"blurb": "Raising an eyebrow in the face of danger, Akshan fights evil with dashing charisma, righteous vengeance, and a conspicuous lack of shirts. He is highly skilled in the art of stealth combat, able to evade the eyes of his enemies and reappear when they...",
"info": {
"attack": 0,
"defense": 0,
"magic": 0,
"difficulty": 0
},
"image": {
"full": "Akshan.png",
"sprite": "champion0.png",
"group": "champion",
"x": 144,
"y": 0,
"w": 48,
"h": 48
},
"tags": [
"Marksman",
"Assassin"
],
"partype": "Mana",
"stats": {
"hp": 560,
"hpperlevel": 90,
"mp": 350,
"mpperlevel": 40,
"movespeed": 330,
"armor": 26,
"armorperlevel": 3,
"spellblock": 30,
"spellblockperlevel": 0.5,
"attackrange": 500,
"hpregen": 3.75,
"hpregenperlevel": 0.65,
"mpregen": 8.175,
"mpregenperlevel": 0.7,
"crit": 0,
"critperlevel": 0,
"attackdamage": 52,
"attackdamageperlevel": 3.5,
"attackspeedperlevel": 4,
"attackspeed": 0.638
}
}
}
}