1.自定义一个类继承JSONEncoder
import json class myEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, bytes): return str(obj,encoding='utf-8') return json.JSONEncoder.default(self, obj)
2.序列化的时候调用
content = json.dumps(dict(item),ensure_ascii=False,cls=myEncoder) + ",\n"