本文介绍了比较JSONArrays的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用我的Andr​​oid应用程序从远程数据库检索JSONArray定制服务。有一次,我检索了JSONArray,我想它的内容比较另一个JSONArray,我称之为'mostRecent。如果新检索JSONArray从'mostRecent不同话,我愿与新检索JSONArray更新mostRecent。如果我没有记错,但是,JSONArray equals方法实例比较JSONArray对象,而不是内容,是否正确?有一种简单的方法来比较两个JSONArrays的内容是什么?感谢您的帮助!

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!

推荐答案

使用的:

array1.toString().equals(array2.toString());

也许你将可以使用,即使您收到的琴弦没有构建 JSONArrays ,但你需要确保这两个的格式相同的方式。

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.

这篇关于比较JSONArrays的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:24