[英]Java - unable to map JSON array to object with Spring getForObject()
I have to consume an API RESTful web service. 我必须使用API RESTful Web服务。 At the moment I have to deal with a JSON object which looks like: 目前,我必须处理一个类似于以下内容的JSON对象:
{
"success":true,
"error":"",
"message":"",
"data":[
["USD","US Dollar","11,696", "connected"],
["EUR","Euro","10,733","connected"]
]
}
And this is the class I use in general to hold most endpoints of this web service: 这是我通常用来保存此Web服务的大多数端点的类:
public class Response {
public boolean success;
private String error;
private String message;
private List<Map<Integer, Array>> data;
public String getError() {
return this.error;
}
public String getMessage() {
return this.message;
}
public Map<Integer,Array> getData() {
return this.data.get(0);
}
}
When running, app crashes with: 运行时,应用程序崩溃并显示:
Could not read JSON: Can not deserialize instance of java.util.LinkedHashMap
out of START_ARRAY token
We need to change the type of 'data' from 我们需要更改“数据”的类型
List<Map<Integer, Array>>
to 至
List<List<String>>
I ended up figuring out that what i need is just: 我最终弄清楚我需要的只是:
private List<ArrayList<String>> data;
Worked like a charm. 像魅力一样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.