这个错误通常是由于文件编码问题引起的。您可以尝试在打开文件时指定编码为'utf-8',如下所示:

with open(input_file, 'r', encoding='utf-8') as f:
    data = json.load(f)

同时,在写入文件时也需要指定编码为'utf-8',如下所示:

with open(output_file, 'w', encoding='utf-8') as f:
    json.dump(new_data, f, ensure_ascii=False)

这样可以确保正确处理包含非ASCII字符的文本数据。

解决Python UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 23: illegal multibyte sequence 错误

原文地址: https://www.cveoy.top/t/topic/p95C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录