在 Python 中读取双序列化 json 文件
Read double serialized json file in Python
我有一个双重序列化的 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)))
如何读取 Python 中的 file_double_serialized.json
并创建一个普通(单序列化)json 文件?
只需反转过程:
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)
我有一个双重序列化的 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)))
如何读取 Python 中的 file_double_serialized.json
并创建一个普通(单序列化)json 文件?
只需反转过程:
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)