首页 > 编程语言 >java比较json对象是否相等

java比较json对象是否相等

时间:2024-07-08 18:23:05浏览次数:16  
标签:zhangguoxiang 26 相等 java sitTest json FILE 20 com

一、需求

需要对比这2个json字符串是否完全一样(不用管顺序)

1 String dui = "{\"adGroupVO\":{\"campaignId\":\"CAMPAIGN201912101000004559\",\"adGroupChannel\":{\"channelType\":\"SMS\",\"resourceCode\":\"TEMPLATE_CODE\"},\"deliveryScene\":\"default\",\"adGroupTimeConfigVO\":{\"startDate\":\"2020-01-02\",\"endDate\":\"2020-01-04\",\"adGroupTimeConfigDetailVoList\":[{\"endTime\":\"20:11\",\"startTime\":\"09:11\"}]},\"adGroupScheduleConfig\":{\"periodic\":false,\"excludeDate\":[\"\"],\"periodInfo\":\"{}\"},\"eventConfig\":{},\"crowdTargetingList\":[{\"bizDate\":\"20191226\",\"principalType\":\"USER_ID\",\"crowdDesc\":\"\",\"crowdId\":\"191226200530888\",\"crowdName\":\"ZGX_已映射_会员域1W用户(清洗后)\",\"crowdSource\":\"FILE\",\"crowdStatus\":1,\"crowdTotalCount\":10000,\"crowdType\":\"FILE\",\"dataUpdateDate\":\"20191226\",\"dataUpdateType\":\"ONCE\",\"expireDate\":\"20201220\",\"fileContentList\":[],\"fileName\":\"会员域人群(清洗后)10000个用户.txt\",\"gmtCreate\":\"2019-12-26 20:05:51\",\"gmtModified\":\"2019-12-26 20:05:51\",\"gmtModifier\":\"[email protected]\",\"gmtModifierId\":\"[email protected]\",\"groupConditions\":[],\"operatorId\":\"[email protected]\",\"operatorName\":\"[email protected]\",\"ossPath\":\"\",\"parentTaskName\":\"\",\"projectName\":\"\",\"sceneId\":\"DEFAULT\",\"storeType\":\"\",\"tableName\":\"\",\"tenantId\":\"DANAW3ID\",\"userIdColumn\":\"\",\"userIdType\":\"USER_ID\",\"userProperty\":\"\",\"useSceneType\":\"TARGETING\"}],\"fatigueLimitVOList\":[],\"name\":\"任务名称_20200102194954313\",\"priority\":1,\"ruleTargetingVOList\":[],\"terminalTargetingList\":[],\"contentVOList\":[{\"creativeVOList\":[{\"name\":\"测试\",\"creativeType\":\"TEXT\",\"creativeDetailVoList\":[{\"language\":\"en_US\",\"defaultOrNot\":true,\"variables\":\"{\\\"text\\\":\\\"内容\\\",\\\"title\\\":\\\"标题\\\"}\"}],\"extendInfo\":\"{\\\"isEmpty\\\":false}\",\"shunt\":100}]}],\"bizType\":\"content_task\",\"adgroupAwardInfoVO\":{}}}";2 String cuo = "{\"adGroupVO\":{\"contentVOList\":[{\"creativeVOList\":[{\"shunt\":100,\"creativeType\":\"TEXT\",\"creativeDetailVoList\":[{\"variables\":\"{\\\"text\\\":\\\"内容\\\",\\\"title\\\":\\\"标题\\\"}\",\"defaultOrNot\":true,\"language\":\"en_US\"}],\"name\":\"测试\",\"extendInfo\":\"{\\\"isEmpty\\\":false}\"}]}],\"bizType\":\"content_task\",\"campaignId\":\"CAMPAIGN201912101000004559\",\"adGroupScheduleConfig\":{\"excludeDate\":[\"\"],\"periodic\":false,\"periodInfo\":\"{}\"},\"priority\":1,\"eventConfig\":{},\"terminalTargetingList\":[],\"adGroupTimeConfigVO\":{\"endDate\":\"2020-01-04\",\"adGroupTimeConfigDetailVoList\":[{\"startTime\":\"09:11\",\"endTime\":\"20:11\"}],\"startDate\":\"2020-01-02\"},\"fatigueLimitVOList\":[],\"name\":\"任务名称_20200102194954313\",\"deliveryScene\":\"default\",\"adgroupAwardInfoVO\":{},\"adGroupChannel\":{\"resourceCode\":\"TEMPLATE_CODE\",\"channelType\":\"SMS\"},\"ruleTargetingVOList\":[],\"crowdTargetingList\":[{\"fileName\":\"会员域人群(清洗后)10000个用户.txt\",\"gmtModified\":\"2019-12-26 20:05:51\",\"parentTaskName\":\"\",\"bizDate\":\"20191226\",\"userIdType\":\"USER_ID\",\"userProperty\":\"\",\"crowdSource\":\"FILE\",\"crowdId\":\"191226200530888\",\"crowdType\":\"FILE\",\"operatorName\":\"[email protected]\",\"tableName\":\"\",\"userIdColumn\":\"\",\"sceneId\":\"DEFAULT\",\"expireDate\":\"20201220\",\"crowdDesc\":\"\",\"operatorId\":\"[email protected]\",\"crowdName\":\"ZGX_已映射_会员域1W用户(清洗后)\",\"ossPath\":\"\",\"crowdStatus\":1,\"storeType\":\"\",\"groupConditions\":[],\"gmtModifierId\":\"[email protected]\",\"crowdTotalCount\":10000,\"gmtCreate\":\"2019-12-26 20:05:51\",\"fileContentList\":[],\"dataUpdateType\":\"ONCE\",\"gmtModifier\":\"[email protected]\",\"useSceneType\":\"TARGETING\",\"dataUpdateDate\":\"20191226\",\"tenantId\":\"DANAW3ID\",\"projectName\":\"\",\"principalType\":\"USER_ID\"}]}}";

二、对比

2.1、思路:2个顺序不一样的json字符串 通过 JSONObject.parse(dui)打印出来后 顺序就是一摸一样的了(前提:key都一样) 然后再通过一个字符串查询就行了

2.2、实现:

 

 

2.3、打印后

1 {"adGroupVO":{"contentVOList":[{"creativeVOList":[{"shunt":100,"creativeType":"TEXT","creativeDetailVoList":[{"variables":"{\"text\":\"内容\",\"title\":\"标题\"}","defaultOrNot":true,"language":"en_US"}],"name":"测试","extendInfo":"{\"isEmpty\":false}"}]}],"bizType":"content_task","campaignId":"CAMPAIGN201912101000004559","adGroupScheduleConfig":{"excludeDate":[""],"periodic":false,"periodInfo":"{}"},"priority":1,"eventConfig":{},"terminalTargetingList":[],"adGroupTimeConfigVO":{"endDate":"2020-01-04","adGroupTimeConfigDetailVoList":[{"startTime":"09:11","endTime":"20:11"}],"startDate":"2020-01-02"},"fatigueLimitVOList":[],"name":"任务名称_20200102194954313","deliveryScene":"default","adgroupAwardInfoVO":{},"adGroupChannel":{"resourceCode":"TEMPLATE_CODE","channelType":"SMS"},"ruleTargetingVOList":[],"crowdTargetingList":[{"fileName":"会员域人群(清洗后)10000个用户.txt","gmtModified":"2019-12-26 20:05:51","parentTaskName":"","bizDate":"20191226","userIdType":"USER_ID","userProperty":"","crowdSource":"FILE","crowdId":"191226200530888","crowdType":"FILE","operatorName":"[email protected]","tableName":"","userIdColumn":"","sceneId":"DEFAULT","expireDate":"20201220","crowdDesc":"","operatorId":"[email protected]","crowdName":"ZGX_已映射_会员域1W用户(清洗后)","ossPath":"","crowdStatus":1,"storeType":"","groupConditions":[],"gmtModifierId":"[email protected]","crowdTotalCount":10000,"gmtCreate":"2019-12-26 20:05:51","fileContentList":[],"dataUpdateType":"ONCE","gmtModifier":"[email protected]","useSceneType":"TARGETING","dataUpdateDate":"20191226","tenantId":"DANAW3ID","projectName":"","principalType":"USER_ID"}]}}

2 {"adGroupVO":{"contentVOList":[{"creativeVOList":[{"shunt":100,"creativeType":"TEXT","creativeDetailVoList":[{"variables":"{\"text\":\"内容\",\"title\":\"标题\"}","defaultOrNot":true,"language":"en_US"}],"name":"测试","extendInfo":"{\"isEmpty\":false}"}]}],"bizType":"content_task","campaignId":"CAMPAIGN201912101000004559","adGroupScheduleConfig":{"excludeDate":[""],"periodic":false,"periodInfo":"{}"},"priority":1,"eventConfig":{},"terminalTargetingList":[],"adGroupTimeConfigVO":{"endDate":"2020-01-04","adGroupTimeConfigDetailVoList":[{"startTime":"09:11","endTime":"20:11"}],"startDate":"2020-01-02"},"fatigueLimitVOList":[],"name":"任务名称_20200102194954313","deliveryScene":"default","adgroupAwardInfoVO":{},"adGroupChannel":{"resourceCode":"TEMPLATE_CODE","channelType":"SMS"},"ruleTargetingVOList":[],"crowdTargetingList":[{"fileName":"会员域人群(清洗后)10000个用户.txt","gmtModified":"2019-12-26 20:05:51","parentTaskName":"","bizDate":"20191226","userIdType":"USER_ID","userProperty":"","crowdSource":"FILE","crowdId":"191226200530888","crowdType":"FILE","operatorName":"[email protected]","tableName":"","userIdColumn":"","sceneId":"DEFAULT","expireDate":"20201220","crowdDesc":"","operatorId":"[email protected]","crowdName":"ZGX_已映射_会员域1W用户(清洗后)","ossPath":"","crowdStatus":1,"storeType":"","groupConditions":[],"gmtModifierId":"[email protected]","crowdTotalCount":10000,"gmtCreate":"2019-12-26 20:05:51","fileContentList":[],"dataUpdateType":"ONCE","gmtModifier":"[email protected]","useSceneType":"TARGETING","dataUpdateDate":"20191226","tenantId":"DANAW3ID","projectName":"","principalType":"USER_ID"}]}}
————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/weixin_35275922/article/details/114560695

标签:zhangguoxiang,26,相等,java,sitTest,json,FILE,20,com
From: https://www.cnblogs.com/fswhq/p/18061054

相关文章

  • Java并发基础
    多线程的出现是要解决什么问题的?本质什么?CPU、内存、I/O设备的速度是有极大差异的,为了合理利用CPU的高性能,平衡这三者的速度差异,计算机体系结构、操作系统、编译程序都做出了贡献,主要体现为:CPU增加了缓存,以均衡与内存的速度差异;//导致可见性问题操作系统增加了进程......
  • 获取Echarts的geoJson文件(省市/区县)
    1.获取市的级别直接使用阿里云提供的工具直接获取: https://datav.aliyun.com/portal/school/atlas/area_selector#&lat=32.62087018318113&lng=118.43261718749999&zoom=4和 https://map.easyv.cloud/和 https://geojson.hxkj.vip/  2.获取县和区的细到街道的geoJson,需......
  • 如何优化Java中的文件读写性能?
    如何优化Java中的文件读写性能?大家好,我是微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!1.使用缓冲流提升文件读写效率1.1.使用BufferedInputStream和BufferedOutputStream在Java中,使用缓冲流可以显著提升文件读写的效率,尤其是对于大文件而言。以下是一个简单......
  • 使用Java构建可靠的分布式缓存系统
    使用Java构建可靠的分布式缓存系统大家好,我是微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!1.分布式缓存系统概述在现代软件架构中,分布式缓存系统扮演着至关重要的角色,它能够显著提升系统的性能和扩展性。本文将探讨如何使用Java构建一个可靠的分布式缓存系统,利......
  • 深入理解Java中的反射与动态代理
    深入理解Java中的反射与动态代理大家好,我是微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!1.反射介绍在Java编程中,反射(Reflection)是指在运行时动态获取类的信息并操作类或对象的能力。Java的反射机制允许程序在运行时获取类的信息(例如类的方法、字段、注解等),并且......
  • Java 如何在volatile内部调用接口
    在Java中,volatile关键字通常用于确保变量的可见性和有序性,而不是用来修饰接口或方法调用的。volatile修饰的变量会被立即同步到主存,并且在每次访问时都会从主存中重新读取,而不是从缓存中读取。这意味着对volatile变量的修改对所有线程都是可见的。然而,我们的需求似乎是在一个被......
  • java实现excel导出和导入
    1.固定化模板导入导出/***注意:需要指定列宽*@createTime2022/4/2216:59*@param:filename文件名*@param:columnList列名别名宽度*@param:orderList数据源*示例*ArrayList<String[]>columnList=newArrayList<String[]>(){{*add(n......
  • Java计算机毕业设计基于的健身俱乐部管理系统(开题报告+源码+论文)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景随着健康意识的普及和生活水平的提高,健身已成为现代人追求健康生活方式的重要组成部分。健身俱乐部作为提供专业健身服务和指导的场所,其管理效率和服......
  • Java计算机毕业设计水果销售平台的设计与实现(开题+源码+论文)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景随着人们生活水平的提高和健康意识的增强,水果作为富含营养、美味可口的天然食品,其市场需求日益增长。然而,传统水果销售模式存在信息不对称、供应链冗......
  • Java计算机毕业设计基于的动漫网站设计与实现(开题报告+源码+论文)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景在数字化时代,动漫文化作为一种独特的艺术形式,在全球范围内拥有庞大的粉丝群体。随着互联网技术的飞速发展,动漫爱好者们越来越倾向于通过线上平台获取......