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)