1.UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 271: illegal multibyte sequence
原因:出现这个错误通常是由于在读取文件时编码格式不匹配导致的。Python 默认使用的编码可能与文件实际编码不同(例如文件编码是 UTF-8,而 Python 试图使用 GBK 编码读取文件)。
解决方法:确保文件使用 UTF-8 编码读取
import json # 假设 JSON 数据存储在一个文件中,例如 'data.json' with open('data.json', 'r', encoding='utf-8') as file: data = json.load(file) # 继续处理 JSON 数据...