1

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)

print


json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 17177 (char 17176)
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.