Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.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 Spring JSON解析错误:带有数组的JSON解析错误。为什么?_Java_Json_Spring_Jackson - Fatal编程技术网

Java Spring JSON解析错误:带有数组的JSON解析错误。为什么?

Java Spring JSON解析错误:带有数组的JSON解析错误。为什么?,java,json,spring,jackson,Java,Json,Spring,Jackson,我正在尝试获取的JSON格式: [ { “id”:“110”, “姓名”:“英格兰”, “区域”:[ { “id”:“1620”, “名称”:“伦敦” }, ... ] }, ... ] dto类别: @数据 公共级WorldDTO{ 私人名单国家; } @资料 私有静态类CountryDTO{ @JsonProperty(value=“id”) 私有字符串id; @JsonProperty(value=“name”) 私有字符串名称; @JsonProperty(value=“areas”)

我正在尝试获取的JSON格式:

[
{
“id”:“110”,
“姓名”:“英格兰”,
“区域”:[
{
“id”:“1620”,
“名称”:“伦敦”
},
...
]
},
...
]
dto类别:

@数据
公共级WorldDTO{
私人名单国家;
}
@资料
私有静态类CountryDTO{
@JsonProperty(value=“id”)
私有字符串id;
@JsonProperty(value=“name”)
私有字符串名称;
@JsonProperty(value=“areas”)
私人名单领域;
}
@资料
公共类区域{
@JsonProperty(value=“id”)
私有字符串id;
@JsonProperty(value=“name”)
私有字符串名称;
}
我调用API的一段代码:

RequestEntity request=newrequestentity(HttpMethod.GET,uri);
ResponseEntity response=restemplate.exchange(请求,新的参数化TypeReference(){});
WorldDTO dto=response.getBody();
在我看来,由于字段private
列出了国家,因此可能会发生错误(WorldDTO.class)没有
@JsonProperty
注释。但是json中也没有这个对象的名称


我做错了什么?

你不需要
worlddt来上课

它认为您正在尝试解析一个对象

org.springframework.web.client.RestClientException: Error while extracting response for type [class com.radar.dto.WorldDTO] and content type [application/json;charset=UTF-8]; 
nested exception is org.springframework.http.converter.HttpMessageNotReadableException: 
JSON parse error: Cannot deserialize instance of `com.radar.dto.WorldDTO` out of START_ARRAY token; 
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.radar.dto.WorldDTO` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 1]

您应该使用
响应属性

您不需要
WorldDTO

它认为您正在尝试解析一个对象

org.springframework.web.client.RestClientException: Error while extracting response for type [class com.radar.dto.WorldDTO] and content type [application/json;charset=UTF-8]; 
nested exception is org.springframework.http.converter.HttpMessageNotReadableException: 
JSON parse error: Cannot deserialize instance of `com.radar.dto.WorldDTO` out of START_ARRAY token; 
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.radar.dto.WorldDTO` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 1]
您应该使用
响应属性