[英]How to use volley in android to extract specific json?
If my request returns a JSON object like this如果我的请求像这样返回 JSON object
{"autocomplete":["abc", "asd"]}
How can I get the array in the JSON and turn it into java ArrayList?如何获取JSON中的数组并将其转换为java ArrayList?
I find some methods like getString, getInt.我找到了一些方法,比如 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.