我尝试从json字段中的多个值中获取一个值。我使用这个for循环从json文件中获取数据:
for i in data['issues']:
x = [i]
for j in x:
pprint(j['fields']['assignee'])
这就是我的回报:
{'active': True,
'avatarUrls': {'16x16': 'link',
'24x24': 'link',
'32x32': 'link',
'48x48': 'link'},
'displayName': 'First name, Last name',
'emailAddress': 'name.namek@mail.com',
'name': 'Name',
'self': 'link'}
我试图使用其中一个值,例如我想获得' displayName'
的价值pprint(j['fields']['assignee'][0])
但是在python IDE中我遇到了这个错误:
TypeError: 'NoneType' object is not subscriptable
好的更具体一点我想从这个json得到例如值displayName,如果我在这里粘贴一个完整的json结构,它可能会更容易
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 50,
"total": 4,
"issues": [
{
"expand": "editmeta,renderedFields,transitions,changelog,operations",
"id": "682884",
"self": "https://jira.sabre.com/rest/api/2/issue/682884",
"key": "ENG-664",
"fields": {
"data": "data",
"assignee": {
"self": "link",
"name": "First name Last name",
"emailAddress": "ame.namek@mail.com",
"avatarUrls": {
"16x16": "link",
"24x24": "link",
"32x32": "link",
"48x48": "link"
},
"displayName": "First name Last name",
"active": true
}
}
},
{
"expand": "editmeta,renderedFields,transitions,changelog,operations",
"id": "682884",
"self": "https://jira.sabre.com/rest/api/2/issue/682884",
"key": "ENG-664",
"fields": {
"data": "data",
"assignee": {
"self": "link",
"name": "First name Last name",
"emailAddress": "ame.namek@mail.com",
"avatarUrls": {
"16x16": "link",
"24x24": "link",
"32x32": "link",
"48x48": "link"
},
"displayName": "First name Last name",
"active": true
}
}
},
{
"expand": "editmeta,renderedFields,transitions,changelog,operations",
"id": "682884",
"self": "https://jira.sabre.com/rest/api/2/issue/682884",
"key": "ENG-664",
"fields": {
"data": "data",
"assignee": {
"self": "link",
"name": "First name Last name",
"emailAddress": "ame.namek@mail.com",
"avatarUrls": {
"16x16": "link",
"24x24": "link",
"32x32": "link",
"48x48": "link"
},
"displayName": "First name Last name",
"active": true
}
}
},
{
"expand": "editmeta,renderedFields,transitions,changelog,operations",
"id": "682884",
"self": "https://jira.sabre.com/rest/api/2/issue/682884",
"key": "ENG-664",
"fields": {
"data": "data",
"assignee": {
"self": "link",
"name": "First name Last name",
"emailAddress": "ame.namek@mail.com",
"avatarUrls": {
"16x16": "link",
"24x24": "link",
"32x32": "link",
"48x48": "link"
},
"displayName": "First name Last name",
"active": true
}
}
}
]}