如何使用GSON或任何其他序列化工具将此内容解析为POJO模型

huangapple go评论68阅读模式
英文:

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.

{
&quot;data&quot;: {
&quot;help_data&quot;: [{
&quot;Help with delivery&quot;: [{
&quot;Qus&quot;: &quot;Estimating lastmile time&quot;,
&quot;Ans&quot;: &quot;is simply dummy text of the printing and typesetting industry&quot;
},
{
&quot;Qus&quot;: &quot;Task not close&quot;,
&quot;Ans&quot;: &quot;is simply dummy text of the printing and typesetting industry&quot;
}
]
},
{
&quot;General issues&quot;: [{
&quot;Qus&quot;: &quot;Estimating lastmile time&quot;,
&quot;Ans&quot;: &quot;is simply dummy text of the printing and typesetting industry&quot;
},
{
&quot;Qus&quot;: &quot;Batching&quot;,
&quot;Ans&quot;: &quot;is simply dummy text of the printing and typesetting industry&quot;
}
]
},
{
&quot;Legal Terms &amp; Contitions&quot;: [{
&quot;Qus&quot;: &quot;Estimating lastmile time&quot;,
&quot;Ans&quot;: &quot;is simply dummy text of the printing and typesetting industry&quot;
},
{
&quot;Qus&quot;: &quot;Batching&quot;,
&quot;Ans&quot;: &quot;is simply dummy text of the printing and typesetting industry&quot;
}
]
},
{
&quot;FAQs&quot;: [{
&quot;Qus&quot;: &quot;Estimating lastmile time&quot;,
&quot;Ans&quot;: &quot;is simply dummy text of the printing and typesetting industry&quot;
},
{
&quot;Qus&quot;: &quot;Batching&quot;,
&quot;Ans&quot;: &quot;is simply dummy text of the printing and typesetting industry&quot;
}
]
}
]
}
}

答案1

得分: 1

我强烈推荐 http://www.jsonschema2pojo.org/
务必选择源类型为JSON。

英文:

I highly recommend http://www.jsonschema2pojo.org/.
Be sure to select JSON as the source type.

huangapple
  • 本文由 发表于 2020年9月22日 22:50:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/64012290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定