【发布时间】:2021-09-28 11:40:32
【问题描述】:
我想通过 Volley for 循环在“media_gallery_entries”JSONArray 中获取“文件”
排球
val item = ArrayList<RecyData>()
val jsonRequest = object : JsonObjectRequest(Request.Method.GET, url, null,
Response.Listener { response ->
try {
val jsonArrayItems = response.getJSONArray("items")
val jsonSize = jsonArrayItems.length()
for (i in 0 until jsonSize) {
val jsonObjectItems = jsonArrayItems.getJSONObject(i)
val pName = jsonObjectItems.getString("name")
val pPrice = jsonObjectItems.getInt("price")
item.add(RecyData(pName, pPrice, pImage))
}
} catch (e: JSONException) {
e.printStackTrace()
}
数据
{
"items": [
{
"id": 1,
"sku": "10-1001",
"name": "item01",
"price": 100,
"media_gallery_entries": [
{
"id": 1,
"file": "//1/0/10-28117_1_1.jpg"
}
]
}
]
}
【问题讨论】:
标签: android arrays json kotlin android-volley