我试图解析这个json并从中提取一个pojo。网上的文件把我弄糊涂了。我怀疑我错误地处理了一个事实,即同一类型的物体有许多不同的发生。我需要阵列吗?那会是什么样子?这是我目前的课程:
public class StoryGSONClass {
private Response kind;
public static class Response {
private String Listing;
private Data data;
}
public static class Data {
private String modhash;
private Children children;
private String after;
private String before;
}
public static class Children {
private String childKind;
private ChildData childData;
}
public static class ChildData {
private String domain;
private String banned_by;
private String media_embed;
private String subreddit;
private String selftext_html;
private String selftext;
private String likes;
private String link_flair_text;
private String id;
private String clicked;
private String title;
private String num_comments;
private String score;
private String approved_by;
private String over_18;
private String hidden;
private String thumbnail;
private String subreddit_id;
private String edited;
private String link_flair_css_class;
private String author_flair_css_class;
private String downs;
private String saved;
private String is_self;
private String permalink;
private String name;
private String created;
private String url;
private String author_flair_text;
private String author;
private String created_utc;
private String media;
private String num_reports;
private String ups;
}
}
然后
Gson gson = new Gson();
StoryGSONClass target2 = gson.fromJson(objectName, StoryGSONClass.class);
编辑:以下是该类的最新版本:
public class Response {
private String kind;
private ResponseData data;
public static class ResponseData {
private String modhash;
private List<ResponseChildData> children;
private String after;
private String before;
}
public static class ResponseChildData {
private String kind;
private ChildData data;
}
public static class ChildData {
private String domain;
private String banned_by;
private Object media_embed;
private String subreddit;
private String selftext_html;
private String selftext;
private String likes;
private String link_flair_text;
private String id;
private boolean clicked;
private String title;
private int num_comments;
private int score;
private String approved_by;
private boolean over_18;
private boolean hidden;
private String thumbnail;
private String subreddit_id;
private boolean edited;
private boolean link_flair_css_class;
private boolean author_flair_css_class;
private int downs;
private boolean saved;
private boolean is_self;
private String permalink;
private String name;
private String created;
private String url;
private String author_flair_text;
private String author;
private String created_utc;
private String media;
private String num_reports;
private int ups;
}
}
1条答案
按热度按时间tct7dpnv1#
主父对象应该如下所示:
那么
ResponseData
是:以及
ResponseChildData
是:最后,
ChildData
是:然后你可以做: