如何比较2 JSONS的值?

时间:2022-04-03 13:36:43

How do I compare whether the values are lesser than or equal between 2 jsons?

如何比较2 jsons之间的值是否小于或等于?

I have a Json :

我有一个Json:

{"item1":{"443189342":0,"438702562":5,"437211162":0,"496545602":0,"444776102":0},"item2":{"443189342":4,"438702562":2,"437211162":2,"496545602":5,"444776102":22}}

As for now I am doing :

至于现在我在做:

  private static void compareValues(ObjectNode value1, ObjectNode value2) {
        assertEquals(value1, value2);
    }

But I would like to assert if the values are off threshold (0.05) ? I mean how do I verify whether the values are same or value1 lesser than value2 ?

但我想声明这些值是否超出阈值(0.05)?我的意思是如何验证值是否相同或value1是否小于value2?

1 个解决方案

#1


0  

First copy pasta some json into http://www.jsonschema2pojo.org/ This will give you a nice java class for the object! Then You want to extend Comparable in that class. This will require you to override the compartor. See link below.

首先将一些json的面食复制到http://www.jsonschema2pojo.org/这将为您提供一个很好的java类对象!然后你想在该类中扩展Comparable。这将要求您覆盖隔离专区。见下面的链接。

http://javarevisited.blogspot.com/2011/11/how-to-override-compareto-method-in.html Good luck man!!

http://javarevisited.blogspot.com/2011/11/how-to-override-compareto-method-in.html祝你好运!

#1


0  

First copy pasta some json into http://www.jsonschema2pojo.org/ This will give you a nice java class for the object! Then You want to extend Comparable in that class. This will require you to override the compartor. See link below.

首先将一些json的面食复制到http://www.jsonschema2pojo.org/这将为您提供一个很好的java类对象!然后你想在该类中扩展Comparable。这将要求您覆盖隔离专区。见下面的链接。

http://javarevisited.blogspot.com/2011/11/how-to-override-compareto-method-in.html Good luck man!!

http://javarevisited.blogspot.com/2011/11/how-to-override-compareto-method-in.html祝你好运!