以下是json内容,如何使用python提取“GBL_ACTIVE_CPU”的值。
{
"test": "00.00.004",
"Metric Payload": [
{
"ClassName": "test",
"SystemId": "test",
"uri": "http://test/testmet",
"MetaData": [
{
"FieldName": "GBL_ACTIVE_CPU",
"DataType": "STRING",
"Label": "test",
"Unit": "string"
}
],
"Instances": [
{
"InstanceNo": "0",
"GBL_ACTIVE_CPU": "4"
}
]
]
}
Run Code Online (Sandbox Code Playgroud)
我试过下面的代码,但不起作用。任何帮助表示赞赏:
result = json.loads(jsonoutput)
print(result)
node = result["Metric Payload"]["Instances"]["GBL_ACTIVE_CPU"]
print(node)
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:
TypeError: list indices must be integers or slices, not str
Run Code Online (Sandbox Code Playgroud)