你能帮我提个建议吗:)
我有json文件,比如:
{
content: {
hostname01: {
active_checks_enabled: "1",
current_attempt: "1",
plugin_output: "SSH OK",
services: {
monitoring: {
active_checks_enabled: "0",
current_attempt: "1",
current_state: "0",
downtimes: { },
plugin_output: "PASV MONITORNG OK",
last_check: "1437382990",
problem_has_been_acknowledged: "0",
}
},
comments: { },
last_notification: "0",
max_attempts: "5"
},
如何格式化这个大文件,使我只有如下对象:
{
hostname01:{
monitoring: {
current_state: "1"
}
}
}
有两种可能的当前状态:0、1。 提前谢谢!你知道吗
使用valid JSON输入,您可以使用模块^{} 读取数据(我猜是从一个文件中读取的,这里我将把它放入代码中):
然后循环遍历主机名并保存来自
current_state
的值。你知道吗输出:
您必须确保所有
hostname
节点具有相同的结构,或者捕获并处理KeyError
异常。你知道吗相关问题 更多 >
编程相关推荐