【发布时间】:2017-11-29 06:30:50
【问题描述】:
我正在尝试从具有内部数组的 JSON 字符串中获取 Java 对象,有几乎相同的问题,但没有一个无法解决我的问题。现在在控制台中我得到 MethodPackage.JsonDeserialize@6580cfdd (我正在使用 objectmapper) 我的目标是在 json 中分别获取值来做一些操作
下面是我的完整代码:
JSONstring:
{
"status": 1,
"message": "ok",
"sheduleCod": "NOST_A_Persons_m_noaccum",
"algorithms": [{
"cod": "No_st_alg_1",
"kcp": "U6000427",
"dtBeg": "2017-11-01 00:00:00",
"dtEnd": "2017-12-01 00:00:00"
}, {
"cod": "No_st_alg_2",
"kcp": "U6000427",
"dtBeg": "2017-11-01 00:00:00",
"dtEnd": "2017-12-01 00:00:00"
}, {
"cod": "No_st_alg_3",
"kcp": "U6000427",
"dtBeg": "2017-11-01 00:00:00",
"dtEnd": "2017-12-01 00:00:00"
}]
}
Main.class
String jsonString = response.toString();
JsonDeserialize deserialize = objectMapper.readValue(jsonString, JsonDeserialize.class);
System.out.println(deserialize);}
JsonDeserialize.class
public class JsonDeserialize {
private String status;
private String message;
private String sheduleCod;
private List<Algorithm> algorithms;
in JsonDeserialize.class
public class JsonDeserialize {
private String status;
private String message;
private String sheduleCod;
private List<Algorithm> algorithms;
public JsonDeserialize(String status, String message, String sheduleCod, List<Algorithm> algorithms) {
this.status = status;
this.message = message;
this.sheduleCod = sheduleCod;
this.algorithms = algorithms;
}
..... and then getters and setters
Algorithm.class
public class Algorithm {
private String cod;
private String kcp;
private String dtBeg;
private String dtEnd;
public Algorithm(String cod, String kcp, String dtBeg, String dtEnd) {
this.cod = cod;
this.kcp = kcp;
this.dtBeg = dtBeg;
this.dtEnd = dtEnd;
}
public Algorithm () {
}
【问题讨论】:
标签: java json objectmapper