我正在尝试编码包含字节字符串的字典 json
得到一个 is not JSON serializable error
。
示例代码:
import base64
import json
data={}
encoded = base64.encodebytes(b'data to be encoded')
data['bytes']=encoded
print(json.dumps(data))
我收到的错误:
TypeError: b'ZGF0YSB0byBiZSBlbmNvZGVk\n' is not JSON serializable
如何正确编码包含JSON字节的字典?