user1522804
user1522804

Reputation: 149

Android:How to convert HttpResponse to List<Object>

I have android AsynTask method that call the Web Service which returns the List<> as shown below:

[[1,"Test",37.334542,-121.890821,-121.890821],
[2,"XYZ",37.337749,-121.886702,-121.886702],
[4,"PQR",37.336453,-121.884985,-121.884985]]

Here my question is how can I convert the response of HttpResponse to List<> as same as shown above.

Upvotes: 0

Views: 1459

Answers (1)

Mike T
Mike T

Reputation: 4787

That looks like a json response. If it is, the easiest way to do it if you have that String (jsonResponse) already is something like:

JSONArray json;
try {
    json = new JSONArray (jsonResponse);
} catch (JSONException e) {
    //do something
}

You can then just use the JSONArray as is, or iterate through it and add each item to a List if you need.

Upvotes: 2

Related Questions