1There are garbled characters in the json file, I want to ignore it, I used the errors='ignore' parameter, but it still prompts errors
My json example: {"network":"lin","id":null,"url":"lin.org/in/dirk-åå¾·å-67172","username":"dirk-åå¾·å-67172"}
import csv
import json
import sys
import codecs
def trans(path):
jsonData = codecs.open('C:/Users/jeri/Desktop/1.json', 'r',
encoding='utf-8', errors='ignore')
csvfile = open('C:/Users/jeri/Desktop/1.csv', 'w', encoding='utf-8',
newline='', errors='ignore')
writer = csv.writer(csvfile, delimiter=',')
flag = True
for line in jsonData:
dic = json.loads(line)
if flag:
keys = list(dic.keys())
print(keys)
writer.writerow(keys)
flag = False
writer.writerow(list(dic.values()))
jsonData.close()
csvfile.close()
if __name__ == '__main__':
path = str(sys.argv[0])
print(path)
trans(path)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 17177 (char 17176)