为什么我会得到out-of-start\u对象令牌错误?

ie3xauqp  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(217)

我试图使用一个大的json响应。我一直收到这个错误:org.springframework.http.converter.httpMessageNotradableException:json解析错误:无法反序列化的示例 java.util.ArrayList<com.justinswork.Corona.Tracking.Model.CountryDailyDataByProvince> 启动外对象令牌
下面是我试图解析的json:(这只是数组的一个索引)。

{
"data":[
0:{
"date":"2020-04-16"
"confirmed":991
"deaths":6
"recovered":984
"confirmed_diff":0
"deaths_diff":0
"recovered_diff":0
"last_update":"2020-04-09 01:12:20"
"active":1
"active_diff":0
"fatality_rate":0.0061
"region":{6 items
"iso":"CHN"
"name":"China"
"province":"Anhui"
"lat":"31.8257"
"long":"117.2264"
"cities":[0 items
]
}
}

我试图用jackson解析它,但它一直返回outofstart\u对象令牌错误。
这是我对外部api的调用,因为您可以看到im使用列表作为响应类型,这使我对为什么会出现这个错误感到困惑。

ResponseEntity<List<CountryDailyDataByProvince>> response = template.exchange(
                "https://covid-19-statistics.p.rapidapi.com/reports?region_name={country}&date=2020-04-16",
                HttpMethod.GET,
                httpEntity, new ParameterizedTypeReference<List<CountryDailyDataByProvince>>()  {
                }, date, country);

        List<CountryDailyDataByProvince> list = response.getBody();

这里是我想解析json的类。

public class CountryDailyDataByProvince {

    private int confirmed;
    private int recovered;
    private int deaths;
    private int active;
    private String province;
    @JsonProperty( "region" )
    private List<String> regions;

    public CountryDailyDataByProvince(int confirmed, int recovered, int deaths, int active, String province,
            List<String> regions) {
        super();
        this.confirmed = confirmed;
        this.recovered = recovered;
        this.deaths = deaths;
        this.active = active;
        this.province = province;
        this.regions = regions;
    }

我真的不明白我为什么会犯这个错误。任何和所有的投入将不胜感激。
编辑:
有人指出我发布的json不是原始json,这里是原始json:

{

    "data": [{
            "date": "2020-04-16",
            "confirmed": 991,
            "deaths": 6,
            "recovered": 984,
            "confirmed_diff": 0,
            "deaths_diff": 0,
            "recovered_diff": 0,
            "last_update": "2020-04-09 01:12:20",
            "active": 1,
            "active_diff": 0,
            "fatality_rate": 0.0061,
            "region": {
                "iso": "CHN",
                "name": "China",
                "province": "Anhui",
                "lat": "31.8257",
                "long": "117.2264",
                "cities": {

                }
            }
        }

    ]
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题