Я пытаюсь получить запрос и получить массив в json, но у меня возникает ошибка, подобная этой:
org.json.JSONException: Value [] of type org.json.JSONArray cannot be converted to JSONObject
вот мой код запроса:
private fun getStudents(endLink: String) {
val request = JSONObject()
val studentLink = "https://192.168.1.1/getStudents.php?idEntity="
val linkFull = studentLink.plus(endLink)
val jsArrayRequest = JsonObjectRequest(Request.Method.GET, linkFull, request, Response.Listener<JSONObject> {
val builder = GsonBuilder()
val gson = builder.create()
val student =
gson.fromJson<Students>(it.toString(), students::class.java!!)
studentResponse = studentResponse
//updateInfo()
}, Response.ErrorListener {
Log.d("ERRORKA", it.message)
Toast.makeText(
this.context,
it.message, Toast.LENGTH_SHORT
).show()
})
MySingleTon.getInstance(this.context!!).addToRequestQue(jsArrayRequest)
}
также моймодели данных:
class StudentResponse {
var groupNumber: String = ""
var students: List<Students>? = null
}
вот 2-й:
class Students {
val id: Int = 0
val firstName: String? = ""
val lastName: String? = ""
val middleName: String? = ""
val email: String? = ""
}