# 比較兩個json是否相等
def equal_json(json1, json2, key):
if isinstance(json1, dict):
for key1 in json2:
if key1 not in json1:
return "json1不存在%s這個key" % key1
for key2 in json1:
if key2 in json2:
dict_result = cmp_json(json1[key2], json2[key2], key2)
if dict_result != "true":
return dict_result
else:
return "json2中不存在%s這個key" % key2
elif isinstance(json1, list):
"""若為list格式"""
result = cmp_json_array(json1, json2, key)
if result != "true":
return result
else:
if str(json1) != str(json2):
return key + "不相等:" + str(json1) + ":" + str(json2)
return "true"