这是我的 JSON 数据:
[
{
"page": 0,
"threads": [
{
"no": 498507562,
"last_modified": 1375984181
},
{
"no": 498503346,
"last_modified": 1375984243
},
{
"no": 498497523,
"last_modified": 1375984241
},
{
"no": 498496579,
"last_modified": 1375984241
},
{
"no": 498499114,
"last_modified": 1375984240
},
{
"no": 498503169,
"last_modified": 1375984239
},
{
"no": 498497038,
"last_modified": 1375984239
},
{
"no": 498501946,
"last_modified": 1375984238
},
{
"no": 498507181,
"last_modified": 1375984237
},
{
"no": 498505625,
"last_modified": 1375984236
},
{
"no": 498505578,
"last_modified": 1375984242
},
{
"no": 498507346,
"last_modified": 1375984236
},
{
"no": 498497504,
"last_modified": 1375984236
},
{
"no": 498486742,
"last_modified": 1375984234
},
{
"no": 498502590,
"last_modified": 1375984232
}
]
},
{
"page": 1,
"threads": [
{(...so on)
这是我的反序列化代码:
Gson gson = new Gson();
JSONArray pageJson = JsonReader.readJsonArrayFromUrl(
"https://api.4chan.org/b/threads.json");
System.out.println(pageJson.toString());
PageResponse PageResponse = gson.fromJson(pageJson.toString(), PageResponse.class);
我在 PageResponse 上收到错误消息。这是我的 PageResponce 课程。我想我可能会正确处理信息。我只使用过 JsonObjects。我想知道如何获取“page”:0,然后如何获取“threads”
public class PageResponse {
List<Page> pages;
public List<Page> getPages() {
return pages;
}
}
我的页面类
公共类页面{
int page;
public int getPage() {
return page;
}
}