从JSON解析所有特定键值并将它们放在列表中?

问题描述 投票:-1回答:1

我有这个JSON:

{
   "ID": "42871",
   "playerid": "226790",
   "position": "CDM",
   "resource_id": "50558438",
   "playername": "Onyinye Ndidi",
   "common_name": "Ndidi",
   "club_name": "Leicester City",
   "nation_name": "Nigeria",
   "league_name": "Premier League",
   "ps_LCPrice": "72000",
   "pc_LCPrice": "85000",
   "xbox_LCPrice": "81500"
},
{
   "ID": "42871",
   "playerid": "226790",
   "position": "CDM",
   "resource_id": "50558438",
   "playername": "Kai Havertz",
   "common_name": "Havertz",
   "club_name": "Bayer 04 Leverkusen",
   "nation_name": "Nigeria",
   "league_name": "Premier League",
   "ps_LCPrice": "44000",
   "pc_LCPrice": "55000",
   "xbox_LCPrice": "99000"
},

我想这样获得输出:

playername, xbox_LCPrice
playername, xbox_LCPrice

所以它先处理第一个数组,然后处理第二个数组,一直到最后,我该怎么做?

json python-3.x
1个回答
0
投票

尝试一下

with open(config_file) as f:
    config_dict = json.load(f)

player_name = config_dict['playername']
© www.soinside.com 2019 - 2024. All rights reserved.