我正在使用Google Details API
我正在使用Jackson作为解析器。
我有以下字符串:
{"close":{"day":0,"time":"2200"},"open":{"day":0,"time":"1500"}}
所以我使用了ObjectMapper:
ObjectMapper mapDetail = new ObjectMapper();
Timetab timetab = mapDetail.readValue(time.get(s), Timetab.class);
Timetab类的位置是:
public class Timetab {
public static class Close{
private int day;
private String time;
public String getTime() {return time;}
public void setTime(String time) {this.time = time;}
public int getDay() {return day;}
public void setDay(int day) {this.day = day;}
}
public static class Open{
private int day;
private String time;
public int getDay() {return day;}
public void setDay(int day) {this.day = day;}
public String getTime() {return time;}
public void setTime(String time) {this.time = time;}
}
private Close cl;
private Open op;
public Close getCl() {return cl;}
public void setCl(Close cl) {this.cl = cl; }
public Open getOp() {return op;}
public void setOp(Open op) {this.op = op;}
}
我收到了以下错误:
05:38:37,816 ERROR TaskUtils $ LoggingErrorHandler:95 - 计划任务中发生意外错误。 org.codehaus.jackson.map.exc.UnrecognizedPropertyException:无法识别的字段“close”
有人可以帮我吗?
谢谢
答案 0 :(得分:3)
Jackson将JSON属性映射到JavaBean属性。因此,JSON属性close
被映射到类close
中的bean属性Timetab
,该属性不存在,因为您将bean属性命名为cl
而不是{{1 }}
请注意,bean属性的名称是从getter或setter的名称派生的,而不是字段本身。所以可以(但不建议)仍然有一个字段close
:
cl