如何在Python3中对json格式数据进行分析处理

  介绍

如何在Python3中对json格式数据进行分析处理?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。


展示一下zabbix的接口返回的json数据(数据经过转储编码了,因为原数据为str类型,只有一行,不易读)

js =, json.dumps (get_alert(),,缩进=4,ensure_ascii=False)   打印(js)   #,get_alert()方法为获取json数据,编码后赋给js,打印js,结果如下:   4 #,indent =,意为设置缩进为4个空格,   #,ensure_ascii=False参数是禁用ascii编码,若不禁用,中文字符会输出为ascii码 {   ,“jsonrpc":“2.0“,   ,“result":,   {才能   ,才能“triggerid":,“123456”,   ,才能“expression":,“{23567}在95“,   ,才能“description":,“High  memory  utilization 祝辞,95,,   ,才能“url":,““,   ,才能“status":,“0”,   ,才能“value":,“1”,   ,才能“priority":,“4“,   ,才能“lastchange":,“123456”,   ,才能“comments":,““,   ,才能“error":,““,   ,才能“templateid":,“0”,   ,才能“type":,“0”,   ,才能“state":,“0”,   ,才能“flags":,“0”,   ,才能“recovery_mode":,“0”,   ,才能“recovery_expression":,““,   ,才能“correlation_mode":,“0”,   ,才能“correlation_tag":,““,   ,才能“manual_close":,“0”,   ,才能“opdata":,““,   ,才能“hosts":,   ,,,{   ,,,,“hostid":,“8888”,   ,,,,“name":,“window_sever"   ,,,}   ,,,,   ,才能“items":,   ,,,{   ,,,,“itemid":,“123456”,   ,,,,“name":,“Memory  utilization"   ,,,,“description":,“Memory  used  percentage  is  calculated  as  (100 - pavailable)“;   ,,,}   ,,,)   ,,},   {才能   ,才能“triggerid":,“17099”,   ,才能“expression":,“{20221} & lt; {$ SWAP.PFREE.MIN.WARN},以及{20222}在0“,   ,才能“description":,“High  swap  space  usage  (, less  than  20%,免费的)“,   ,才能“url":,““,   ,才能“status":,“0”,   ,才能“value":,“1”,   ,才能“priority":,“2”,   ,才能“lastchange":,“123456789”,   ,才能“comments":,“却;能够trigger  is 忽视,,if  there  is  no  swap  configured"   ,才能“error":,““,   ,才能“templateid":,“16176”,   ,才能“type":,“0”,   ,才能“state":,“0”,   ,才能“flags":,“0”,   ,才能“recovery_mode":,“0”,   ,才能“recovery_expression":,““,   ,才能“correlation_mode":,“0”,   ,才能“correlation_tag":,““,   ,才能“manual_close":,“0”,   ,才能“opdata":,“免费的:,{ITEM.LASTVALUE1},,总:{ITEM.LASTVALUE2}“,   ,才能“hosts":,   ,,,{   ,,,,“hostid":,“10325”,   ,,,,“name":,“linus"   ,,,}   ,,,,   ,才能“items":,   ,,,{   ,,,,“itemid":,“31681”,   ,,,,“name":,“Free  swap  space  %“拷贝,   ,,,,“description",:,“,   ,,,},   ,,,{   ,,,,“itemid":,“123456”,   ,,,,“name":,“Total  swap  space"   ,,,,“description",:,“,   ,,,}   ,,,)   ,,}   ,),   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

如何在Python3中对json格式数据进行分析处理