问题
I am currently using a custom service in my android application to retrieve a JSONArray from a remote database. Once I have retrieved the JSONArray, I would like to compare its contents to another JSONArray which I call 'mostRecent.' If the newly retrieved JSONArray differs from 'mostRecent' then I would like to update 'mostRecent' with the newly retrieved JSONArray. If I am not mistaken, however, the JSONArray equals method compares the instance of the JSONArray object and not the contents, correct? Is there an easy method to compare the contents of two JSONArrays? Thanks for the help!
回答1:
Use that:
array1.toString().equals(array2.toString());
Maybe you will be able to use even the strings you receive without constructing the JSONArrays
, but then you will need to make sure the two are formatted the same way.
来源:https://stackoverflow.com/questions/9454064/comparing-jsonarrays