我从服务器 {"status":"true","msg":"success"}
得到这个响应
我尝试使用 Jackson 解析器库来解析这个 json 字符串,但是不知怎么的,我遇到了映射-异常声明
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: java.io.StringReader@421ea4c0; line: 1, column: 1]
为什么我们会有这种例外?
如何理解是什么导致了这个异常?
我尝试使用以下方法进行解析:
StatusResponses loginValidator = null;
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(Feature.AUTO_CLOSE_SOURCE, true);
try {
String res = result.getResponseAsString();//{"status":"true","msg":"success"}
loginValidator = objectMapper.readValue(result.getResponseAsString(), StatusResponses.class);
} catch (Exception e) {
e.printStackTrace();
}
StatusResponse 类
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "status","msg" })
public class StatusResponses {
@JsonProperty("status")
public String getStatus() {
return status;
}
@JsonProperty("status")
public void setStatus(String status) {
this.status = status;
}
@JsonProperty("msg")
public String getMessage() {
return message;
}
@JsonProperty("msg")
public void setMessage(String message) {
this.message = message;
}
@JsonProperty("status")
private String status;
@JsonProperty("msg")
private String message;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonGetter
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
@JsonSetter
public void setAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
}
}