Comparing JSONArrays

浪尽此生 提交于 2019-12-11 04:38:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!