If my request returns a JSON object like this
{"autocomplete":["abc", "asd"]}
How can I get the array in the JSON and turn it into java ArrayList?
I find some methods like getString, getInt. But I don't find a method that could get the array.
CodePudding user response:
val response = JSONObject(yourresponse)
val Jarray: JSONArray = response.getJSONArray("autocomplete")
for (i in 0 until Jarray.length()) {
val jsonobject: JSONObject = jsonarray.getJSONObject(i)
Log.e("TAG",jsonobject.toString())
}
In this way you can do
CodePudding user response:
String response = new JSONObject(response);
JSONArray array= c.getJSONArray("autocomplete");
for (int i = 0; i < array.length(); i ){
JSONObject a = carteVisite.getJSONObject(j);
Log.d("TAG", a);
}