我正在尝试将下面的这个 json 解析为一个名为的对象AlbumResponse
,其中包含另外两个对象,Album
并且PaginationInfo
. 改造 2.0 版
[
{
"id": "6",
"name": "King Stays King",
"artist_name":"Timbaland",
"image":""
},
{
"id": "7",
"name": "East Atlanta Santa 2",
"artist_name":"Gucci Mane",
"image":""
},
{
"id": "8",
"name": "The cuban connect",
"artist_name":"Phophit",
"image":""
},
{
"id": "9",
"name": "Shmoney Keeps",
"artist_name":"Calling",
"image":""
},
{
"id": "10",
"name": "Cabin Fever 3",
"artist_name":"Wiz khalifa",
"image":""
}
],
{
"nextPage": "http://private-ede172-mymixtapez1.apiary-mock.com/features/page_3/",
"itemsTotal": 10,
"page": 2,
"pagerMax": 2
}
专辑类
public class Album {
long id;
String name;
@SerializedName("artist_name")
String artistName;
String image;
}
分页信息类
public class PaginationInfo {
int page;
int pagerMax;
int nextPage;
int itemsTotal;
}
AlbumResponse,里面有两个类,并且Album
是List
public class AlbumResponse {
public List<Album> albums;
public PaginationInfo paginationInfo;
}
请求
Call<AlbumResponse> responseCall = albumService.features();
responseCall.enqueue(new Callback<AlbumResponse>() {
@Override
public void onResponse(Response<AlbumResponse> response, Retrofit retrofit) {
if(response.isSuccess()) {
AlbumResponse albumResponse = response.body();
PaginationInfo paginationInfo = albumResponse.getPaginationInfo();
}
System.out.println();
}
@Override
public void onFailure(Throwable t) {
System.out.println(t.getMessage());
}
});
界面
public interface AlbumService {
@GET("/features/")
Call<AlbumResponse> features();
}
问题是我得到一个Throwable
包含:
com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期 BEGIN_OBJECT 但在第 1 行第 2 列路径 $` 处为 BEGIN_ARRAY
请有人可以帮助我,我在stackoverflow中没有找到任何答案。谢谢。