简体   繁体   中英

Accessing a json object nested in a json array with Python 3.x

Given the json payload below, how do I get the value of 'hotspot' using Python 3.x? The top level seems to be aa dict with one key value pair. 'Recs' is the key and the value is a Python list. I have loaded the json payload into the Python class using json.loads(payload) .

json payload:

{
    'Recs': [{
        'eSrc': 'big-a1',
        'reqPs': {
            'srcIP': '11.111.11.111'
        },
        'a1': {
            'a1Ver': '1.0',
            'obj': {
                'eTag': '38f028e',
                'sz': 1217,
                'seq': '02391D2',
                'hotspot': 'web/acme/srv/dev/8dd'
            },
            'confId': 'acme-contains',
            'pipe': {
                'name': 'acme.dev',
                'oId': {
                    'pId': 'BDAD'
                }
            }
        }
    }]
}

{表示字典, [表示列表,因此hotspot位于:

my_json['Recs'][0]['a1']['obj']['hotspot']

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