I am trying to encode a dictionary containing a string of bytes with json
, and getting a is not JSON serializable error
:
import base64
import json
data = {}
encoded = base64.b64encode(b'data to be encoded')
data['bytes'] = encoded
print(json.dumps(data))
The error I get:
TypeError: b'ZGF0YSB0byBiZSBlbmNvZGVk
' is not JSON serializable
How can I correctly encode my dictionary containing bytes with JSON?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…