gpt4 book ai didi

json - [spring-boot,restTemplate]JSON解析错误: Cannot deserialize value of type XXXX from Object value (token `JsonToken.START_OBJECT` )

转载 作者:行者123 更新时间:2023-12-05 06:00:09 27 4
gpt4 key购买 nike

我使用 Spring-boot 和 RestTemplate。我在从 json 转换为 Dto 时遇到问题。

客户端

Items items = restTemplate.getForObject("https://xxxxx/xxxxx, Items.class);

元素

@Getter
@Setter
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = false)
public class Items {

private List<Item> Items;

public Items() {
Items = new ArrayList<>();
}

@Override
public String toString() {
return String.valueOf(Items.size());
}
}

元素

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Item {

private String title;

@Override
public String toString() {
return "Item{" + "title=" + title + '}';
}

}

Json来了(格式化)

{
"Items": [
{
"Item": {
"limitedFlag": 0,
"authorKana": "XXX",
"author": "XXX",
"subTitle": "XXX",
"seriesNameKana": "XXXX",
"title": "XXXX",
"subTitleKana": "XXXX"
}
},
{
"Item": {
"limitedFlag": 0,
"authorKana": "XXX",
"author": "XXX",
"subTitle": "XXX",
"seriesNameKana": "XXXX",
"title": "XXXX",
"subTitleKana": "XXXX"
}
}
],
"last": 30
}

我收到此错误消息:

Caused by: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `[Ldev.itboot.mb.rest.Item;` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `[Ldev.itboot.mb.rest.Item;` from Object value (token `JsonToken.START_OBJECT`)

我看了这里和谷歌,但仍然无法弄清楚。

任何回应都会有所帮助。

问候。

最佳答案

您的 JSON 结尾似乎不正确,数组之后“last”之前应该有一个逗号。

  ]
"last": 30
}

关于json - [spring-boot,restTemplate]JSON解析错误: Cannot deserialize value of type XXXX from Object value (token `JsonToken.START_OBJECT` ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67830684/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com