Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java toJson-如何使用类的数组设计类_Java_Arrays_Json_Gson - Fatal编程技术网

Java toJson-如何使用类的数组设计类

Java toJson-如何使用类的数组设计类,java,arrays,json,gson,Java,Arrays,Json,Gson,我从Elasticsearch得到一个JSON格式的响应,我希望Gson将其转换为Java类,但是我在如何开发该类方面遇到了困难。以下是返回的JSON: { "took":3, "_shards":{ "total":3, "successful":3, "failed":0 }, "total":1, "matches":[ { "_index":"object_percolator", "_id":"2" },

我从Elasticsearch得到一个JSON格式的响应,我希望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"
    }
]
}
“比赛”让我很难过。如何设计类来处理该数组?有什么想法吗?提前谢谢

类匹配{
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
        }
List matchCollection=new ArrayList(); //在这里添加getter和setter } 类匹配集合{ 私有字符串_索引; 私有整数_id; //在这里添加getter和setter }
//添加需要检索的对象

试着用谷歌搜索一下


答案和信息都很好。谢谢