0

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.


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.

4

1 回答 1

2

这看起来像一个 json 响应。如果是这样,如果您已经拥有该字符串(jsonResponse),那么最简单的方法是:

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

然后,您可以按原样使用 JSONArray,或者遍历它并将每个项目添加到 aList如果需要。

于 2012-08-08T07:13:04.783 回答