public static void jsonObjectsEquals(JSONObject o1,JSONObject o2) throws JSONException {
  if (o1 != o2) {
    if (o1.length() != o2.length()) {
      fail("JSONObjects length differ: " + o1.length() + " / "+ o2.length());
    }
    @SuppressWarnings("unchecked") Iterator<String> o1Keys=o1.keys();
    while (o1Keys.hasNext()) {
      String key=o1Keys.next();
      Object o1Value=o1.get(key);
      Object o2Value=o2.get(key);
      if (!jsonValueEquals(o1Value,o2Value)) {
        fail("JSONObject '" + key + "' values differ: "+ o1Value+ " / "+ o2Value);
      }
    }
  }
}

public static void jsonObjectsEquals ( JSONObject o1 , JSONObject o2 ) throws JSONException { if ( o1 != o2 ) { if ( o1 . length ( ) != o2 . length ( ) ) { fail ( "JSONObjects length differ: " + o1 . length ( ) + " / " + o2 . length ( ) ) ; } @ SuppressWarnings ( "unchecked" ) Iterator < String > o1Keys = o1 . keys ( ) ; while ( o1Keys . hasNext ( ) ) { String key = o1Keys . next ( ) ; Object o1Value = o1 . get ( key ) ; Object o2Value = o2 . get ( key ) ; if ( ! jsonValueEquals ( o1Value , o2Value ) ) { fail ( "JSONObject '" + key + "' values differ: " + o1Value + " / " + o2Value ) ; } } } }
assert that two jsonobjects are equals without enforcing field order .
