简体   繁体   中英

How to erase/delete curly brackets/braces from a dictionary?

My JSON response looks like this. I want to remove curly brackets (with ** around it) so I can get the values in the card key. Can I do that or is it gonna mess up the entire Dictionary? If so, I want to assign key-value before curly brackets (with ** around it ).

Hope someone can help me with this and if you can give me a further explanation about a dictionary in python I would be thrilled!

[
    **{**
        "board": {
            "id": "5f2106f0a188d073ebf3604b",
            "name": "TrAPI_test",
            "shortLink": "OIeEN1vG"
        },
        "card": {
            "id": "5f236a13a64ee90e7ef95341",
            "idShort": 3,
            "name": "task3",
            "shortLink": "WNHiHWxh"
        },
        "idMember": "5e1d96663a14c86d44d0edc4",
        "member": {
            "id": "5e1d96663a14c86d44d0edc4",
            "name": "Zorigt"
        }
    **}**,
    {
        "board": {
            "id": "5f2106f0a188d073ebf3604b",
            "name": "TrAPI_test",
            "shortLink": "OIeEN1vG"
        },
        "card": {
            "id": "5f236a13a64ee90e7ef95341",
            "idShort": 3,
            "name": "task3",
            "shortLink": "WNHiHWxh"
        },
        "list": {
            "id": "5f22161e221bea80b90d96ad",
            "name": "SprintTask"
        }
    }

]

I was able to get it like this because it was a list of multiple dictionaries all along:))

{
    "0": {
        "board": {
            "id": "5f2106f0a188d073ebf3604b",
            "name": "TrAPI_test",
            "shortLink": "OIeEN1vG"
        },
        "card": {
            "id": "5f236a13a64ee90e7ef95341",
            "idShort": 3,
            "name": "task3",
            "shortLink": "WNHiHWxh"
        },
        "idMember": "5e1d96663a14c86d44d0edc4",
        "member": {
            "id": "5e1d96663a14c86d44d0edc4",
            "name": "Zorigt"
        }
    },
    "1": {
        "board": {
            "id": "5f2106f0a188d073ebf3604b",
            "name": "TrAPI_test",
            "shortLink": "OIeEN1vG"
        },
        "card": {
            "id": "5f236a13a64ee90e7ef95341",
            "idShort": 3,
            "name": "task3",
            "shortLink": "WNHiHWxh"
        },
        "list": {
            "id": "5f22161e221bea80b90d96ad",
            "name": "SprintTask"
        }
    }
}

Use this

Dict_convert= {}
for idx, val in enumerate(List): 
    Dict_convert[idx] = val 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM