I execute async request (REST query
). Getting response from server side is...
[{"id":2,"name":"Flowers"},{"id":3,"name":"Trees"}]
I need to parse response string to JSONObject
and then to
ArrayList<Map<String, String>>
In my next async
method of getting data (some code is commented):
//async getting data
@Override
public void onSuccessResult(String response) {
String message;
Log.d(Constants.LOG, response);
try {
JSONObject jsonResponse = new JSONObject(response);
/*
JSONArray jsonArray = jsonResponse.getJSONArray("id");
data.clear();
for(int i=0;i<jsonArray.length()-1;i++){
HashMap<String, String> m = new HashMap<String, String>();
JSONArray url = jsonArray.getJSONArray(i);
m.put("name", url.getString(0));
dataPlants.add(m);
//sAdapter.notifyDataSetChanged();
*/
}catch (JSONException e) {
Log.d(Constants.LOG, e.toString());
e.printStackTrace();
}
I get the next exception
:
org.json.JSONException: Value
[{"id":2,"name":"Flowers"},{"id":3,"name":"Trees"}] of type org.json.JSONArray cannot be converted to JSONObject
So, how to proceed response
appropriately