比較兩個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