1

我正在创建一个 python 脚本来提取jboss-cli.sh默认情况下以以下格式返回输出的值:

    {
        “结果” => “成功”,
        “结果” => {
            "活动计数" => "0",
            "可用计数" => "0",
            "平均阻塞时间" => "0",
            "平均创建时间" => "0",
            "CreatedCount" => "0",
            "DestroyedCount" => "0",
            "InUseCount" => "0",
            "MaxCreationTime" => "0",
            "MaxUsedCount" => "0",
            "MaxWaitCount" => "0",
            "MaxWaitTime" => "0",
            "超时" => "0",
            "TotalBlockingTime" => "0",
            "TotalCreationTime" => "0",
            “启用统计” => false
        }
    }

现在我使用以下代码将其转换为 JSON 格式:

from jbossply.jbossparser import JbossParser parser = JbossParser() print(parser.parse(OUT))

所以它给出的输出为:

{u'outcome': u'success', u'result': {u'AverageBlockingTime': u'0', u'AvailableCount': u'0', u'statistics-enabled': False, u'MaxCreationTime': u'0', u'MaxUsedCount': u'0', u'CreatedCount': u'0', u'MaxWaitCount': u'0', u'TimedOut': u'0', u'InUseCount': u'0', u'ActiveCount': u'0', u'TotalBlockingTime': u'0', u'DestroyedCount': u'0', u'AverageCreationTime': u'0', u'TotalCreationTime': u'0', u'MaxWaitTime': u'0'}}

现在如何从中提取“AvailableCount”。试过 json.load 但不工作。

4

2 回答 2

2

尝试这个!

from jbossply.jbossparser import JbossParser
import json

parser = JbossParser()
parser_out = parser.parse(OUT)
json_dump = json.dump(parser_out)
json_load = json.loads(json_dump)
print json_load['result']['AvailableCount']
# op 0
于 2018-03-23T09:47:53.123 回答
0

最后我自己得到了答案,将 json 解析为一个变量并提取如下结果:

parser = JbossParser() data=(parser.parse(OUT)) TOTAL_CN=(data["result"]["AvailableCount"])

于 2018-03-23T09:48:22.003 回答