I have the following Array element returned with json_encode . My question is how to take that array named ArrayName by retrofit...
{
"ArrayNombre": [
{
"idUser": "180",
"Nombre": "Aaron",
}
]
}
Inside the onResponse of the retrofit query I take the data using
ArrayList mArrayList=new ArrayList<>(response.body());
The data is filled in taken through the Interface
@GET("posts")
Call<List<Posts>> getPosts();
I have no problem if the json_encode is returned without an array name, but if the array has a name like in this case I can't get the data. How do you have to enter the array?
With volley he did it through
JSONArray json=response.optJSONArray("ArrayNombre");
One possible problem is the retrofit interface:
You have indicated that you expect a list of posts, but the JSON is an object that has the ArrayName attribute inside, which is a list:
So you should create something like the following, I don't know if you are using GSON and I haven't seen your data model either:
And change the interface: