[英]JSON and Cryptography With Python: TypeError: Object of type bytes is not JSON serializable
[英]Python TypeError: Object of type 'bytes' is not JSON serializable
我想打开并解析一个 JSON 文件,但我不断收到以下错误:
TypeError: Object of type 'bytes' is not JSON serializable
这是我的代码,
class FileStore(object):
def __init__(self, filePath, data = None):
self.filePath = filePath
self.data = data
def store_json(self):
with open(self.filePath, 'w') as outfile:
json.dump(self.data, outfile) # this is where the error occurs
请帮我解决这个问题?
尝试这个:
json.dump(self.data.decode(), outfile)
如果您的数据有效但只有Bytes
这将解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.