简体   繁体   English

使用Python 3.x访问嵌套在json数组中的json对象

[英]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? 给定下面的json有效负载,如何使用Python 3.x获取“ hotspot”的值? The top level seems to be aa dict with one key value pair. 顶级似乎是一个具有一对键值对的字典。 'Recs' is the key and the value is a Python list. “ Recs”是键,值是Python列表。 I have loaded the json payload into the Python class using json.loads(payload) . 我已经使用json.loads(payload)将json负载加载到Python类中。

json payload: json有效负载:

{
    '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']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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