I was trying to get list of students from the following json using Retrofit2
{
"students":[
{
"address":{
"city":"DETROIT",
"state":"MI",
"street":"4904 Yorkshire Circle",
"zip":"48228"
},
"school":"A B C D School",
"name":"Mani Nezhad"
},
{
"address":{
"city":"RED HOOK",
"state":"NY",
"street":"1641 Custer Street",
"zip":"12571"
},
"school":"X Y Z School",
"name":"Jane Lindberg"
}
]
}
Here is my Model Class
data class Student(
val name: String,
val school: String,
val address: Address
) {
data class Address(val street: String, val city: String, val state: String, val zip: String)
And here is the method written in Interface:
@GET("abcd")
fun getStudents(@Query("token") token: String): Call<List<Student>>
but whenever I run the app I get this error
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
I understand that I was trying to getch array from a json which starts with { curly bracket.
Now my question is how can I fetch this student array from this type of json which starts with the curly bracket?