读取文件,文件里每一行都是一个字典
{"report": "Worm:Win32/Sfone", "is_null": 1, "pcap": "02161a7bb79f901b2cd9ff95866c1f5b.pcap"}
{"report": "TrojanDropper:Win32/Dinwod", "is_null": 1, "pcap": "013995355cd4e237a7ac974e83a3dc20.pcap"}
{"report": "Trojan:Win32/Wacatac.D4!ml", "is_null": 1, "pcap": "00c15844efe4f5a7034795e283b65d6d.pcap"}
{"report": "Worm:Win32/Sfone", "is_null": 1, "pcap": "027e98dbf1e06a27cb44406307ffa48f.pcap"}
{"report": "Worm:Win32/Sfone", "is_null": 1, "pcap": "06d2499ee049aad79cdb07651ebb85b4.pcap"}
with open(file_name,'r') as f:
lines = f.readlines() #一下都读到内存,然后生成一个列表
for line in lines:
info = json.loads(line) #json.loads将字符串转化为字典
也可以这样写:
js_file = open(file_name,'r')
for line in js_file:
if line == '\n':
continue
if line.strip():
info = json.loads(line)
print(info)