[英]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.