如果我有一个嵌套的字典,我如何在python中访问字典值



我有一个字典的结构,我需要对它进行迭代,以确定在键"items"下以及键字段后面的键"toString"下是否有值"status"和值"In Progress"。

此外,我需要得到它发生的日期。这可以在更高一级的关键字"created"下查找值。

我尝试了很多方法,但都没有成功。我感谢你的帮助。

{'startAt': 0,
'maxResults': 18,
'total': 18,
'histories': [{'id': '126221979',
'author': {'self': '<some_URL>',
'name': '<ID in the system>',
'key': '<ID in the system>',
'emailAddress': 'e-mail address',
'avatarUrls': {'48x48': '<some_URL>',
'24x24': '<some_URL>',
'16x16': '<some_URL>',
'32x32': '<some_URL>'},
'displayName': 'Display Name',
'active': True,
'timeZone': 'America/Sao_Paulo'},
'created': '2022-02-11T19:22:40.000+0000',
'items': [{'field': 'Link',
'fieldtype': 'jira',
'from': None,
'fromString': None,
'to': '<Isue ID>',
'toString': 'This issue child-of <Some ID>'}]},
{'id': '126221981',
'author': {'self': '<some_URL>',
'name': '<ID in the system>',
'key': '<ID in the system>',
'emailAddress': 'e-mail address',
'avatarUrls': {'48x48': '<some_URL>',
'24x24': '<some_URL>',
'16x16': '<some_URL>',
'32x32': '<some_URL>'},
'displayName': 'Display Name',
'active': True,
'timeZone': 'America/Sao_Paulo'},
'created': '2022-02-11T19:23:56.000+0000',
'items': [{'field': 'status',
'fieldtype': 'jira',
'from': 1,
'fromString': 'Open',
'to': 3,
'toString': 'In Progress'}
]
},
{'id': '126221981',
'author': {'self': '<some_URL>',
'name': '<ID in the system>',
'key': '<ID in the system>',
'emailAddress': 'e-mail address',
'avatarUrls': {'48x48': '<some_URL>',
'24x24': '<some_URL>',
'16x16': '<some_URL>',
'32x32': '<some_URL>'},
'displayName': 'Display Name',
'active': True,
'timeZone': 'America/Sao_Paulo'},
'created': '2022-02-11T19:23:56.000+0000',
'items': [{'field': 'status',
'fieldtype': 'jira',
'from': 1,
'fromString': 'Open',
'to': 3,
'toString': 'In Progress'}
]
}
]
}

使用pd_json_normalize:

>>> pd.json_normalize(d['histories'], 'items', 'created')
field fieldtype  from fromString         to                       toString                       created
0    Link      jira   NaN       None  <Isue ID>  This issue child-of <Some ID>  2022-02-11T19:22:40.000+0000
1  status      jira   1.0       Open          3                    In Progress  2022-02-11T19:23:56.000+0000
2  status      jira   1.0       Open          3                    In Progress  2022-02-11T19:23:56.000+0000

最新更新