python - Json序列化和反序列化
问题描述
我正在使用 python 中的 deepdiff 包比较两个嵌套字典。我想将它存储在一个文件中,但它给了我一个错误
'prettyordered set 不是 json 可序列化的'
我尝试使用它进行转换'to_dict'
,同样的错误。我也尝试使用 转换它'to_json'
,它解决了问题,但它在键和值中添加了反斜杠,而且在阅读时我无法阅读,它给了我一个错误:
'json.decoder.JSONDecodeError'
from deepdiff import DeepDiff
import json
variable1={'key':'key32','hello':'hello1'}
variable2={"key3":'key','hello':'hello2'}
result=DeepDiff(variable1,variable2)
result=result.to_json()
print(result)
filename='json_serializable'+'.txt'
objects_file = 'D:\\'+ filename
f = open(objects_file,'w')
f.write(json.dumps(result))
with open('D:\\Registryvalues\\'+filename) as json_file:
variable1 = json.load(json_file)
print(variable1)
我想编写和读取我使用 deepdiff 获得的差异对象。有人可以帮助我吗?
解决方案
推荐阅读
- android - 如何根据 Firestore 中的特定字段从集合中获取所有文档
- python - Wireshark 如何解释十六进制值?
- regex - 使用正则表达式在 Notepad++ 中设置差异
- python - 部署到 GoogleAPP ENGINE
- python-3.x - 如何从列表中搜索值并应用 np.where 条件?
- spring - Hibernate 验证错误的模式
- java - JAR 文件正在运行,但没有显示窗口/GUI
- node.js - 解析 XLSX 并转换为对象
- nginx - NGINX - lua-resty-openidc - 无法访问 POST api url
- reactjs - 如何对屏蔽输入进行单元测试?