JSON列出集合中的所有标识

时间:2016-04-28 11:26:19

标签: python json set

我最近开始使用JSON。下面的代码显示了我正在使用的代码片段。在这个例子中,我想提取集合{1411,1410,2009,3089}。 JSON是否为此提供了方法,还是我需要自己创建它?

如果它是相关的,我正在使用Python。

{
  "1411": {
     "id": 1411,
     "plaintext": "Increases Attack Speed, and gives increasing power as you kill Jungle Monsters and Champions",
     "description": "<stats>+40% Attack Speed<br>+30 Magic Damage on Hit<\/stats><br><br><unique>UNIQUE Passive - Devouring Spirit:<\/unique> Takedowns on large monsters and Champions increase the magic damage of this item by +1. Takedowns on Rift Scuttlers and Rift Herald increase the magic damage of this item by +2. Takedowns on Dragon and Baron increase the magic damage of this item by +5. At 30 Stacks, your Devourer becomes Sated, granting extra on Hit effects.",
     "name": "Enchantment: Devourer",
     "group": "JungleItems"
  },
  "1410": {
     "id": 1410,
     "plaintext": "Grants Ability Power and periodically empowers your Spells",
     "description": "<stats>+60 Ability Power<br>+7% Movement Speed<\/stats><br><br><unique>UNIQUE Passive - Echo:<\/unique> Gain charges upon moving or casting. At 100 charges, the next damaging spell hit expends all charges to deal 60 (+10% of Ability Power) bonus magic damage to up to 4 targets on hit.<br><br>This effect deals 250% damage to Large Monsters. Hitting a Large Monster with this effect will restore 18% of your missing Mana.",
     "name": "Enchantment: Runic Echoes",
     "group": "JungleItems"
  },
  "2009": {
     "id": 2009,
     "description": "<consumable>Click to Consume:<\/consumable> Restores 80 Health and 50 Mana over 10 seconds.",
     "name": "Total Biscuit of Rejuvenation"
  },
  "3089": {
     "id": 3089,
     "plaintext": "Massively increases Ability Power",
     "description": "<stats>+120 Ability Power  <\/stats><br><br><unique>UNIQUE Passive:<\/unique> Increases Ability Power by 35%.",
     "name": "Rabadon's Deathcap"
  }

2 个答案:

答案 0 :(得分:1)

不,JSON根本不提供任何方法或任何方法。 JSON只是一种表示数据的格式,仅此而已。

答案 1 :(得分:0)

正如其他人所说,JSON是一种格式,并不提供任何API。由于您使用的是python,您可以做的是

import json
my_data = json.loads(my_json)
print my_data.keys()

我假设您的ID与键相同。此外,由于密钥是唯一的,因此您不需要set