I'm using org.json library in java to read a json file in my java program. I've written the following method to compare two JSON Objects using equals method. However it always returns false even though both objects are the same.
private boolean isContentEqual(JSONObject o1, JSONObject o2) {
boolean isContentEqual = false;
try {
JSONArray contentArray1 = o1.getJSONArray("content");
JSONArray contentArray2 = o2.getJSONArray("content");
if (contentArray1.equals(contentArray2))
isContentEqual = true;
else
isContentEqual = false;
}
catch (Exception e) {
e.printStackTrace();
}
return isContentEqual;
}
When I run this method it always returns false
The json object I'm comparing is
content: [
{
one: "sample text 1",
two: ""
},
{
one: "sample text 2",
two: ""
},
{
one: "sample text 3",
two: ""
},
{
one: "sample text 4",
two: ""
}
]
Why is this happening?