I have 2 jsons like {"a1":{"b1":{"c1":"value1"},"b2":{"c2":{"d2":"value2"}}}}
and {"a1":{"b2":{"c2":{"d2":"value2"}},"b1":{"c1":"value1"}}}
.
I am trying to write a method that compares the 2 jsons.
I have a recursive function, but I don't know how to check whether a json object is nested with other json objects or not (this is required for putting an end criteria in recursion)
Here's my code so far:
public static boolean verifyResponse(JSONObject json1,JSONObject json2)
{
Object keyarray[]=json1.keySet().toArray();
int i=0;
while(i<keyarray.length)
{
if(!verifyResponse((JSONObject)json1.get(keyarray[i].toString()),(JSONObject)json2.get(keyarray[i].toString())))
{
return false;
}
i++;
}
return true;
}