更新时间:2021-07-29 22:54:23
您JSON包含数组,但你试图解析它作为对象。
出现此错误的原因对象必须从启动{
。
Your json contains an array, but you trying to parse it as object.
This error occurs because object must start from {
.
您有2个选项:
您可以摆脱 ShopContainer
类,并使用商店[]
而不是
ShopContainer response = restTemplate.getForObject(
url, ShopContainer.class);
替换
Shop[] response = restTemplate.getForObject(url, Shop[].class);
,然后让物体形成,或任何你需要的。
and then make object form it or whatever you need.
您可以更改您的服务器返回的对象,而不是列表
You can change your server to return object instead of list
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(list);
替换
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(
new ShopContainer(list));