英文:
How to parse this to a POJO model using GSON or any other serializer
问题
import com.google.gson.annotations.SerializedName;
import java.util.List;
import java.util.Map;
public class HelpData {
@SerializedName("data")
private Data data;
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public static class Data {
@SerializedName("help_data")
private List<Map<String, List<QuestionAnswer>>> helpData;
public List<Map<String, List<QuestionAnswer>>> getHelpData() {
return helpData;
}
public void setHelpData(List<Map<String, List<QuestionAnswer>>> helpData) {
this.helpData = helpData;
}
}
public static class QuestionAnswer {
@SerializedName("Qus")
private String question;
@SerializedName("Ans")
private String answer;
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
}
}
Note: Make sure to include the GSON library in your project to parse JSON data into the Java objects.
英文:
Can anyone tell me an approach to parse this response to a Java POJO model using GSON? I am not sure how to create a POJO for this. I am new to Java. Hence any help would be appreciated. I did try to http://jsonviewer.stack.hu/# and i could see the data but it is not giving back the POJO model.
{
"data": {
"help_data": [{
"Help with delivery": [{
"Qus": "Estimating lastmile time",
"Ans": "is simply dummy text of the printing and typesetting industry"
},
{
"Qus": "Task not close",
"Ans": "is simply dummy text of the printing and typesetting industry"
}
]
},
{
"General issues": [{
"Qus": "Estimating lastmile time",
"Ans": "is simply dummy text of the printing and typesetting industry"
},
{
"Qus": "Batching",
"Ans": "is simply dummy text of the printing and typesetting industry"
}
]
},
{
"Legal Terms & Contitions": [{
"Qus": "Estimating lastmile time",
"Ans": "is simply dummy text of the printing and typesetting industry"
},
{
"Qus": "Batching",
"Ans": "is simply dummy text of the printing and typesetting industry"
}
]
},
{
"FAQs": [{
"Qus": "Estimating lastmile time",
"Ans": "is simply dummy text of the printing and typesetting industry"
},
{
"Qus": "Batching",
"Ans": "is simply dummy text of the printing and typesetting industry"
}
]
}
]
}
}
答案1
得分: 1
我强烈推荐 http://www.jsonschema2pojo.org/。
务必选择源类型为JSON。
英文:
I highly recommend http://www.jsonschema2pojo.org/.
Be sure to select JSON as the source type.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论