str = '{"result":1,"content":"成功","meter":[{"cjsj":"2021-10-20 02:48:00.0","bcys":"0.000","jzqzt":"","bh":"","sfbh":"112779","bzt":"","tmh":"20080001910303","ljl":"236.585"},{"cjsj":"2021-10-20 02:53:00.0","bcys":"0.000","jzqzt":"","bh":"","sfbh":"56400","bzt":"用水量突增","tmh":"20080001810303","ljl":"135.301"},{"cjsj":"2021-10-20 02:52:00.0","bcys":"0.000","jzqzt":"","bh":"","sfbh":"56666","bzt":"","tmh":"20080001610303","ljl":"264.216"},{"cjsj":"2021-10-21 02:45:00.0","bcys":"-0.004","jzqzt":"","bh":"","sfbh":"80062","bzt":"用水量为负","tmh":"20080002010303","ljl":"34.951"},{"cjsj":"2021-10-21 02:34:00.0","bcys":"0.000","jzqzt":"","bh":"","sfbh":"81654","bzt":"","tmh":"20080001710303","ljl":"308.576"}]}'
json是采用双引号的,可以将上面这段内容中的",通过html包中的unescape函数还原。
import html
r = html.unescape(str)
j = json.loads(r)
结果如下: {"result":1,"content":"成功","meter":[{"cjsj":"2021-10-20 02:48:00.0","bcys":"0.000","jzqzt":"","bh":"","sfbh":"112779","bzt":"","tmh":"20080001910303","ljl":"236.585"},{"cjsj":"2021-10-20 02:53:00.0","bcys":"0.000","jzqzt":"","bh":"","sfbh":"56400","bzt":"用水量突增","tmh":"20080001810303","ljl":"135.301"},{"cjsj":"2021-10-20 02:52:00.0","bcys":"0.000","jzqzt":"","bh":"","sfbh":"56666","bzt":"","tmh":"20080001610303","ljl":"264.216"},{"cjsj":"2021-10-21 02:45:00.0","bcys":"-0.004","jzqzt":"","bh":"","sfbh":"80062","bzt":"用水量为负","tmh":"20080002010303","ljl":"34.951"},{"cjsj":"2021-10-21 02:34:00.0","bcys":"0.000","jzqzt":"","bh":"","sfbh":"81654","bzt":"","tmh":"20080001710303","ljl":"308.576"}]}
|