Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.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 在rest模板Spring中映射JSONArray_Java_Json_Spring_Resttemplate - Fatal编程技术网

Java 在rest模板Spring中映射JSONArray

Java 在rest模板Spring中映射JSONArray,java,json,spring,resttemplate,Java,Json,Spring,Resttemplate,我正在尝试使用Spring RestTemplate映射此JSONArray: [{ "Command": "/usr/sbin/sshd -D", "Created": 1454501297, "Id": "e00ca61f134090da461a3f39d47fc0cbeda77fbbc0610439d3c16a932686b612", "Image": "ubuntu:latest", "Labels": { }, "Names":

我正在尝试使用Spring RestTemplate映射此JSONArray:

[{
    "Command": "/usr/sbin/sshd -D",
    "Created": 1454501297,
    "Id": "e00ca61f134090da461a3f39d47fc0cbeda77fbbc0610439d3c16a932686b612",
    "Image": "ubuntu:latest",
    "Labels": {

    },
    "Names": [
        "/nova-c1896fbd-1309-4da2-8d77-b4fe4c02fa8e"
    ],
    "Ports": [

    ],
    "Status": "Up 2 hours"
}, {
    "Command": "/usr/sbin/sshd -D",
    "Created": 1450106126,
    "Id": "7ffc9dbdd200e2c23adec442abd656ed57306955332697cb7da979f36ebf3b22",
    "Image": "ubuntu:latest",
    "Labels": {

    },
    "Names": [
        "/nova-93b9ae40-8135-48b7-ac17-12094603b28c"
    ],
    "Ports": [

    ],
    "Status": "Up 2 hours"
}]
以下是
ContainersInfo
class:

@JsonIgnoreProperties(ignoreUnknown = true)
public class ContainersInfo {


    private String Id;


    private List<String> Names;

    public String getId() {
        return Id;
    }

    public void setId(String id) {
        Id = id;
    }

    public List<String> getNames() {
        return Names;
    }

    public void setNames(List<String> names) {
        Names = names;
    }
}
结果输出如下:

id:null

id:null


你知道我该怎么做吗?

你的JSON字段名是用pascal大小写的,而不是驼峰大小写(通常是这样)。将Jackson命名策略设置为
PascalCaseStrategy
,即通过将
@JsonNaming(PascalCastrategy.class)
注释添加到
ContainerInfo
类中。

您确定标签部分是对象吗?或者它应该是数组?我甚至不尝试映射
标签
我只是尝试在
ContainersInfo
classTry中获取
Id
名称
,尝试删除标签。@PradipBorde我做不到,这是我从服务器收到的JSON。是的,我知道chrome扩展以格式化的方式显示JSON数据,改变了这一点。这不是问题所在。
ContainersInfo[] containers = syncRestTemplate.getForObject("http://192.168.1.2:4243/containers/json?all=1", ContainersInfo[].class);

for (int i = 0; i < containers.length; i++)
            System.out.println("id:" + containers[i].getId());