Python 正在与这组混合嵌套的对象作斗争

Python 正在与这组混合嵌套的对象作斗争,python,json,list,dictionary,Python,Json,List,Dictionary,我仍在努力掌握Python中的嵌套对象,并且在尝试从该数据结构(使用.json()方法从网站XHR请求返回)中提取我想要的内容时有点放松: 这是XML HTTP请求,用于填充包含足球数据的网站上的表。可以使用网站上的下拉列表来重现/刷新/重新填充数据。该表包含英超20支球队的数据 我想要的是在较大的嵌套结构中名为u'teamTableStats':的字典列表的内容。其中的每个字典对应一个团队的数据 我尝试过使用代码(其中responser是使用.json()返回的对象): 这将返回如下结果: m

我仍在努力掌握Python中的嵌套对象,并且在尝试从该数据结构(使用.json()方法从网站XHR请求返回)中提取我想要的内容时有点放松:

这是XML HTTP请求,用于填充包含足球数据的网站上的表。可以使用网站上的下拉列表来重现/刷新/重新填充数据。该表包含英超20支球队的数据

我想要的是在较大的嵌套结构中名为
u'teamTableStats':
的字典列表的内容。其中的每个字典对应一个团队的数据

我尝试过使用代码(其中responser是使用.json()返回的对象):

这将返回如下结果:

match =  statColumns
match =  paging
match =  teamTableStats
我真正想要的是:

{u'seasonId': 0, u'ranking': 1,
     u'assistFreekick': 0.0, u'minsPlayed': 810, u'tournamentName': u'Premier League', u'rating': 
    7.35092043142043, u'assistThroughball': 0.4444444444444444, u'tournamentRegionCode': None, u'apps': 
    9, u'seasonName': None, u'teamName': u'Chelsea', u'tournamentRegionId': 252, u'regionCode': u'gb-
    eng', u'teamId': 15, u'assistThrowin': 0.0, u'assistCorner': 0.3333333333333333, u'tournamentId': 2,
     u'assistOther': 1.0, u'assistCross': 0.5555555555555556, u'assist': 0.0, u'name': u'Chelsea'}
...
...
...
{u'seasonId': 0, u'ranking': 20, u'assistFreekick': 0.0, 
    u'minsPlayed': 810, u'tournamentName': u'Premier League', u'rating': 6.681928256928256, 
    u'assistThroughball': 0.0, u'tournamentRegionCode': None, u'apps': 9, u'seasonName': None, 
    u'teamName': u'Aston Villa', u'tournamentRegionId': 252, u'regionCode': u'gb-eng', u'teamId': 24, 
    u'assistThrowin': 0.0, u'assistCorner': 0.0, u'tournamentId': 2, u'assistOther': 0.2222222222222222,
     u'assistCross': 0.0, u'assist': 0.0, u'name': u'Aston Villa'}
返回包含每个团队数据的字典的位置。有人能告诉我我做错了什么,应该使用什么语法吗


谢谢

jsonObject[u'teamTableStats']
将为您提供与teamTableStats相对应的词典列表

然后只需迭代它们,并对它们执行您想要的操作:

teamStatDicts = jsonObject[u'teamTableStats']
for statDict in teamStatDicts:
    print "match =", statDict
{u'seasonId': 0, u'ranking': 1,
     u'assistFreekick': 0.0, u'minsPlayed': 810, u'tournamentName': u'Premier League', u'rating': 
    7.35092043142043, u'assistThroughball': 0.4444444444444444, u'tournamentRegionCode': None, u'apps': 
    9, u'seasonName': None, u'teamName': u'Chelsea', u'tournamentRegionId': 252, u'regionCode': u'gb-
    eng', u'teamId': 15, u'assistThrowin': 0.0, u'assistCorner': 0.3333333333333333, u'tournamentId': 2,
     u'assistOther': 1.0, u'assistCross': 0.5555555555555556, u'assist': 0.0, u'name': u'Chelsea'}
...
...
...
{u'seasonId': 0, u'ranking': 20, u'assistFreekick': 0.0, 
    u'minsPlayed': 810, u'tournamentName': u'Premier League', u'rating': 6.681928256928256, 
    u'assistThroughball': 0.0, u'tournamentRegionCode': None, u'apps': 9, u'seasonName': None, 
    u'teamName': u'Aston Villa', u'tournamentRegionId': 252, u'regionCode': u'gb-eng', u'teamId': 24, 
    u'assistThrowin': 0.0, u'assistCorner': 0.0, u'tournamentId': 2, u'assistOther': 0.2222222222222222,
     u'assistCross': 0.0, u'assist': 0.0, u'name': u'Aston Villa'}
teamStatDicts = jsonObject[u'teamTableStats']
for statDict in teamStatDicts:
    print "match =", statDict