Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

whole file is here:https://1drv.ms/u/s!AizscpxS0QM4hJpFPnbeAexYPwYu9Q

I want from this part:

"subtasks": [
                    {
                        "fields": {
                            "issuetype": {
                                "avatarId": 10316,
                                "description": "The sub-task of the issue",
                                "iconUrl": "https://jira.corp.company.com/secure/viewavatar?size=xsmall&avatarId=10316&avatarType=issuetype",
                                "id": "10101",
                                "name": "Sub-task",
                                "self": "https://jira.corp.company.com/rest/api/2/issuetype/10101",
                                "subtask": true
                            },
                            "priority": {
                                "iconUrl": "https://jira.corp.company.com/images/icons/priorities/medium.svg",
                                "id": "3",
                                "name": "Medium",
                                "self": "https://jira.corp.company.com/rest/api/2/priority/3"
                            },
                            "status": {
                                "description": "",
                                "iconUrl": "https://jira.corp.company.com/",
                                "id": "10000",
                                "name": "Backlog",
                                "self": "https://jira.corp.company.com/rest/api/2/status/10000",
                                "statusCategory": {
                                    "colorName": "blue-gray",
                                    "id": 2,
                                    "key": "new",
                                    "name": "To Do",
                                    "self": "https://jira.corp.company.com/rest/api/2/statuscategory/2"
                                }
                            },
                            "summary": "Remove user account in Local AD"
                            },

to extract "Remove user account in Local AD" (summary field)

So far i have this code:

data = json.load(open(1.json))


for issue in data['issues']:
   print issue['fields']['subtasks']

and getting section above, how to get only summary value ?

if i add:

for issue in data['issues']:
   print issue['fields']['subtasks']['summary']

i get:

 print issue['fields']['subtasks']['summary']
TypeError: list indices must be integers, not str

same with:

    for i in range (0, len (data['issues'])):
       print data['issues']['fields']['subtasks'][i]['fields']['summary']
TypeError: list indices must be integers, not str
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
140 views
Welcome To Ask or Share your Answers For Others

1 Answer

Ah, subtasks is the key, but the item is a list!

So it will be issue['fields']['subtasks'][0]['summary'] what you are looking for.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...