Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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
如何使用Jersey 2.27反序列化客户端站点上的JSON数组_Json_Jackson_Jersey Client - Fatal编程技术网

如何使用Jersey 2.27反序列化客户端站点上的JSON数组

如何使用Jersey 2.27反序列化客户端站点上的JSON数组,json,jackson,jersey-client,Json,Jackson,Jersey Client,这是我目前的代码: public ArrayList<Person> getGames() { WebTarget target = webTarget.path("some/path"); Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON); // add authentication cookie to get request

这是我目前的代码:

    public ArrayList<Person> getGames() {

    WebTarget target = webTarget.path("some/path");

    Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);

//        add authentication cookie to get request
    Response response = invocationBuilder.cookie(this.cookie).get();

    int status = response.getStatus();

    if (status == 200) { // everything ok

        // response has wrong MediaType (text/plain from server side)
        // this sets the right MediaType so Jackson (Json deserialization) will handle it
        response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);

//     How do I do this?
       ArrayList<Person> list = response.readEntity(???);

        return list;
    } else {
        return new ArrayList<GameInfo>(); // FIXME: This may throw an exception
    }
}
这是在内部完成的(我想是和杰克逊)

我的问题是,我得到的JSON格式如下:

[{"name":"name","age":"age","lives":{"street":"myStreet"}}, .... ]
我想这样做是可能的,没有太多麻烦,但我找不到任何例子,不使用非常过时的版本泽西。在文档中,我找不到关于数组反序列化的段落


我感谢任何形式的帮助:)

并回答我自己的问题:

非常感谢webdevnick22

Person[] persons = response.readEntity(Person[].class);
这就是你所要做的,一个简单但很难找到的答案

Person[] persons = response.readEntity(Person[].class);