首页 > 解决方案 > 在python3中计算dict中的键

问题描述

我是 python 新手,我想获取“actionType”键的总数,如果计数大于 2,我需要使用 actiontype、state、severname 创建新的 json。我怎样才能做到这一点。

"actions": [
        {
            "id": "xxx",
            "createdAt": "2012xxx",
            "actionType": "start",
            "state": "failed",
            "serverName": "test1",
        }
        {
            "id": "xxx",
            "createdAt": "2012xxx",
            "actionType": "stop",
            "state": "failed",
            "serverName": "test2",
        }
        {
            "id": "xxx",
            "createdAt": "2012xxx",
            "actionType": "start",
            "state": "failed",
            "serverName": "test3",
        }
        {
            "id": "xxx",
            "executor": "xxxx",
            "createdAt": "2012xxx",
            "actionType": "start",
            "state": "failed",
            "serverName": "test4",
        }
  ]

标签: python-3.8

解决方案


推荐阅读