比较两个json是否相等



# 比较两个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"



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM