我有一個雙重序列化的 json 檔案。該檔案已創建為:
with open('file.json', 'r') as f:
file = json.load(f)
#double serializing json file
with open('file_double_serialized.json', "w") as f:
f.write(json.dumps(json.dumps(file)))
如何file_double_serialized.json在 Python 中閱讀并創建一個普通的(單序列化)json 檔案?
uj5u.com熱心網友回復:
只需反轉該程序:
import json
with open('file_double_serialized.json', "r") as f:
data = json.loads(json.loads(f.read()))
# write correctly
with open('fixed.json','w') as f:
json.dump(data,f)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/429786.html
