【发布时间】:2016-06-18 12:23:30
【问题描述】:
好的!我有一个非常复杂的 JSON,我使用 Retrofit 库通过异步进程对其进行了解析。
实际上,我正在使用 JSON API 解析 Wordpress JSON。我在 recyclerview 适配器中显示所有帖子的标题和内容。
不过,获取新帖子的标题和内容非常容易。我在为它创建 ModelClass 时遇到问题。以下是JSON格式:
{
"status": "ok",
"count": 10,
"count_total": 26,
"pages": 3,
"posts": [
{
"id": 274,
"title": "A ver, very long post!",
"content":"BLAH BLAH",
"excerpt":"BLAH",
"attachments": [
{
"id": 201,
"url": "http://example.com/image.jpg",
"slug": "iamge.jpg",
"title": "iamge.jpg",
"description": "",
"caption": "",
"parent": 274,
"mime_type": "image/jpeg",
"images": {
"full": {
"url": "http://example.com/image.jpg",
"width": 480,
"height": 480
},
"thumbnail": {
"url": "http://example.com/image.jpg",
"width": 150,
"height": 150
},
"medium": {
"url": "http://example.com/image.jpg",
"width": 300,
"height": 300
},
"medium_large": {
"url": "http://example.com/image.jpg",
"width": 480,
"height": 480
},
"large": {
"url": "http://example.com/image.jpg",
"width": 480,
"height": 480
}
}
}
]
}
我的模型类包含以下类变量以及 getter 方法:
private int id;
private String type;
private String slug;
private String url;
private String status;
private String title;
private String title_plain;
private String content;
private String excerpt;
private String date;
private String modified;
private String[] categories;
private String[] tags;
private String author;
private String[] comments;
public ArrayList<AttachmentClass> attachments = new ArrayList<AttachmentClass>();
我的问题在于 ArrayList 附件。附件是字符串类型数据和其他用户定义的类变量的集合......
我可以获取帖子、标题等。但我不知道如何从各种附件的 ArrayList 中获取数据...请帮助...
在适配器类中,我正在使用
private ArrayList<ModelClass> dataset;
String message = dataset.get(getLayoutPosition()).getContent();
String title = dataset.get(getLayoutPosition()).getTitle();
这些调用给了我结果......我只是不知道如何显示来自数据集的数组列表(附件)中的数据......
【问题讨论】:
标签: java android json wordpress arraylist