我有以下 JSON 提要:
{
collection_name: "My First Collection",
username: "Alias",
collection: {
1: {
photo_id: 1,
owner: "Some Owner",
title: "Lightening McQueen",
url: "http://hesp.suroot.com/elliot/muzei/public/images/randomhash1.jpg"
},
2: {
photo_id: 2,
owner: "Awesome Painter",
title: "Orange Plane",
url: "http://hesp.suroot.com/elliot/muzei/public/images/randomhash2.jpg"
}
}
}
我想要做的是获取集合的内容 - photo_id、所有者、标题和 URL。我有以下代码,但是我收到 GSON JSON 错误:
@GET("/elliot/muzei/public/collection/{collection}")
PhotosResponse getPhotos(@Path("collection") String collectionID);
static class PhotosResponse {
List<Photo> collection;
}
static class Photo {
int photo_id;
String title;
String owner;
String url;
}
}
我认为我的代码对于获取 JSON 提要是正确的,但我不太确定。任何帮助表示赞赏。
我得到的错误是:
Caused by: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 75
但是我很难理解如何使用 GSON 库