ypeError: Object of type 'bytes' is not JSON serializable

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"

猜你喜欢

转载自www.cnblogs.com/zqrios/p/9034809.html
今日推荐