Gson.toJson - 如何设计具有类数组的类

时间:2014-04-30 01:09:30

标签: java arrays json gson

我从JSON格式获得了Elasticsearch的回复,我希望Gson能够转换成Java类,但是我无法解决如何开发类的问题。这是返回的JSON:

{
"took":3,
"_shards":{
    "total":3,
    "successful":3,
    "failed":0
},
"total":1,
"matches":[
    {
        "_index":"object_percolator",
        "_id":"2"
    },
    {
        "_index":"object_percolator",
        "_id":"3"
    }
]
}

'匹配'是什么给了我一个艰难的时刻。我如何设计类来处理该数组?有任何想法吗?提前谢谢!

1 个答案:

答案 0 :(得分:0)

class Matches{
   List<MatchesCollection> matchCollection=new ArrayList<MatchesCollection>();
//add getter and setter here
}
      class MatchesCollection {
             private String _index;
             private Integer _id;
             //add getter and setter here
        }

//添加您需要检索的对象

  

尝试谷歌关于POJO

Check this link for creating classes How to create a POJO?