我想将Arraylist> getallAnimals()的内容与我从服务器检索到的json数组进行比较。我从mainactivity调用Arraylist。我怎样才能做到这一点?我的代码在下面..
public ArrayList<HashMap<String, String>> getAllAnimals() {
ArrayList<HashMap<String, String>> wordList;
wordList = new ArrayList<HashMap<String, String>>();
String selectQuery = "SELECT * FROM animals";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
HashMap<String, String> map = new HashMap<String, String>();
map.put("animalId", cursor.getString(0));
map.put("animalName", cursor.getString(1));
wordList.add(map);
} while (cursor.moveToNext());
}
// return contact list
return wordList;
}
我的json代码如下:
//parse json data
try
{
JSONArray jArray = new JSONArray(result);
String s,s1;
Log.w("Lengh",""+jArray.length());
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
s=json_data.getString("Animalname");
//s1=json_data.getString("Type");
Log.i("Animalname",s);
// Log.i("typw",s1);
}
}
catch(JSONException e)
{
Log.e("log_tag", "Error parsing data "+e.toString());
Toast.makeText(getApplicationContext(), "JsonArray fail", Toast.LENGTH_SHORT).show();
}