python报错误:json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig)

源码:
with open(os.getcwd() + "\\category.txt", encoding='utf-8') as file_read:
for line in file_read.readlines():
categorys.append(json.loads(line.strip()))
file_read.close()
print(categorys)

改为:
with open(os.getcwd() + "\\category.txt", encoding='utf-8_sig') as file_read:
for line in file_read.readlines(): # 依次读取每行
categorys.append(json.loads(line.strip()))
file_read.close()
print(categorys)
posted @ 2022-05-07 10:55  向前、向前  阅读(885)  评论(0编辑  收藏  举报