import json
with open('file1.json', 'r') as f:
content1 = f.read()
json1 = json.loads(content1)
with open('file2.json', 'r') as f:
content2 = f.read()
json2 = json.loads(content2)
def deepcompare(obj1, obj2):
if type(obj1) != type(obj2):
return False
if isinstance(obj1, dict) and isinstance(obj2, dict):
if len(obj1) != len(obj2):
return False
for key in obj1:
if key not in obj2:
return False
if not deepcompare(obj1[key], obj2[key]):
return False
return True
elif isinstance(obj1, list) and isinstance(obj2, list):
if len(obj1) != len(obj2):
return False
for i in range(len(obj1)):
if not deepcompare(obj1[i], obj2[i]):
return False
return True
else:
return obj1 == obj2
result = deepcompare(json1, json2)
print(result)
上一篇:比较两个Rx中的可流动流