def jsonProcess(fileName,round):
id = 1
with open(fileName, 'r', encoding='utf-8') as f,open('../tempData/tempFile'+str(round)+'.txt','w') as tempFile:
line = f.readline()
line = f.readline()
temp = ''
khNum = 0
id = 1
while line:
# print(line)
if line.find('{') != -1:
khNum += 1
if line.find('}') != -1:
khNum -= 1
if khNum == 0:
line = line.replace(',','')
data = getUsefullData(temp + line,id)
id += 1
if len(data) > 1:
# print(data)
tempFile.write(json.dumps(data)+'\n')
except 'json.decoder.JSONDecodeError':
break
temp = ''
line = f.readline()
continue
temp += line
line = f.readline()
读取方法:
with open('../tempData/tempFile'+str(round)+'.txt') as f:
dataList = f.readlines()
# 解析保存好的list
for data in dataList:
data = json.loads(data)