简体   繁体   中英

How to use volley in android to extract specific json?

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.

     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

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM