I'm trying to create Java Pojo classes for following Json
https://www.reddit.com/r/MurderedByWords/comments/ervfco/trying_to_relate_to_their_viewers/.json
I just wanted to extract the comments, author, created_utc from the JSON. I couldn't figure it out as it has two arrays.
Can anyone help me to create it?
Edit:
public class Codebeautify {
0 0O bject;
1 1 Object;
// Getter Methods
public 0 get0() {
return 0O bject;
}
public 1 get1() {
return 1 Object;
}
// Setter Methods
public void set0(0 0O bject) {
this .0 Object = 0O bject;
}
public void set1(1 1 Object) {
this .1 Object = 1 Object;
}
}
public class 1 {
private String kind;
Data DataObject;
// Getter Methods
public String getKind() {
return kind;
}
public Data getData() {
return DataObject;
}
// Setter Methods
public void setKind(String kind) {
this.kind = kind;
}
public void setData(Data dataObject) {
this.DataObject = dataObject;
}
}
public class Data {
private String modhash;
private String dist = null;
ArrayList < Object > children = new ArrayList < Object > ();
private String after = null;
private String before = null;
// Getter Methods
public String getModhash() {
return modhash;
}
public String getDist() {
return dist;
}
public String getAfter() {
return after;
}
public String getBefore() {
return before;
}
// Setter Methods
public void setModhash(String modhash) {
this.modhash = modhash;
}
public void setDist(String dist) {
this.dist = dist;
}
public void setAfter(String after) {
this.after = after;
}
public void setBefore(String before) {
this.before = before;
}
}
public class 0 {
private String kind;
Data DataObject;
// Getter Methods
public String getKind() {
return kind;
}
public Data getData() {
return DataObject;
}
// Setter Methods
public void setKind(String kind) {
this.kind = kind;
}
public void setData(Data dataObject) {
this.DataObject = dataObject;
}
}
public class Data {
private String modhash;
private float dist;
ArrayList < Object > children = new ArrayList < Object > ();
private String after = null;
private String before = null;
// Getter Methods
public String getModhash() {
return modhash;
}
public float getDist() {
return dist;
}
public String getAfter() {
return after;
}
public String getBefore() {
return before;
}
// Setter Methods
public void setModhash(String modhash) {
this.modhash = modhash;
}
public void setDist(float dist) {
this.dist = dist;
}
public void setAfter(String after) {
this.after = after;
}
public void setBefore(String before) {
this.before = before;
}
}
JSON returned by the URL in your question is an array having 2 objects.
You can use online tools like jsonschema2pojo to generate the POJO classes (select source type as JSON).
Then you can use any popular json libary like Jackson or GSON to convert the json to POJO.
Root POJOs would be something like
public class Root{
private List<Item> items;
}
public class Item {
private Data data;
private String kind;
}
EDIT: There is a restriction of 51200 characters at jsonschema2pojo . For larger JSON, use sodhanalibrary
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.