defwriteJsonFile(data,outfilename):
with open(outfilename+'.json', 'wt',encoding='utf-8') as f:for m indata:
json.dump(m,f,ensure_ascii=False,indent=4)
f.close()
把两个List写入test.json
deftest():
result=[1,2,3]
temp={'test':result
}
content=[]
content.append(temp)
content.append(temp)
writeJsonFile(content,'test')
于是便有了一个test.json
{
"test": [
1,
2,
3
]
}{
"test": [
1,
2,
3
]
}
那么问题来了。
读取文件
def readJsonFile(file_name):
data =[]
with open(file_name,'r',encoding='utf-8') as f:
data = json.load(f)
f.close()
return data
显示错误:
json.decoder.JSONDecodeError: Extra data: line 7 co