我正在尝试解析这个 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;
}
}