如何在python中以json格式获取键的特定值

时间:2018-04-24 14:15:38

标签: python json

我希望在python中以json格式获得agentName之类的键的特定值。怎么办呢?

{
"metaData": {
    "fields": [
        "id",
        "path",
        "time",
        "userid",
        "type",
        "size",
        "lastProcessed",
        "numProcessed"
    ],
    "queueStatus": {
        "agentId": "publish-xxxxx",
        "agentName": "publish-xxxxx",
        "isBlocked": false,
        "isPaused": false,
        "lastProcessTime": -1,
        "nextRetryPeriod": -1524578525793,
        "processingSince": -1,
        "time": 1524578525792
    },
    "root": "queue"
},
"queue": []
}

1 个答案:

答案 0 :(得分:1)

d={'metaData': {'fields': ['id',
   'path',
   'time',
   'userid',
   'type',
   'size',
   'lastProcessed',
   'numProcessed'],
  'queueStatus': {'agentId': 'publish-xxxxx',
   'agentName': 'publish-xxxxx',
   'isBlocked': False,
   'isPaused': False,
   'lastProcessTime': -1,
   'nextRetryPeriod': -1524578525793L,
   'processingSince': -1,
   'time': 1524578525792L},
  'root': 'queue'},
 'queue': []}
#Code:
In [6]: d['metaData']['queueStatus']['agentName']
Out[6]: 'publish-xxxxx'