public static void main(String[] args) throws JSONException {
String data = "[{'goodsId':'11','goodsq':'10'},{'goodsId':'11','goodsq':'10'},{'goodsId':'113','goodsq':'10'},{'goodsId':'112','goodsq':'10'}]";
JSONArray a = new JSONArray(data);
List<String> list = new ArrayList<String>();
for (int i = 0; i < a.length(); i++) {
JSONObject jo = a.getJSONObject(i);
list.add(jo.toString());
}
int count = 0;
for (int i = 0; i < a.length(); i++) {
JSONObject jo = a.getJSONObject(i);
count += list.indexOf(jo.toString());
}
if (count == a.length()) {
System.out.println("没有重复");
} else {
System.out.println("有重复了");
}
}
还有更好的方法吗?