我试图将一个 json 字符串从 WS 转换为我自己的 Java POJO,但找不到方法。
这是我从 WS 得到的回复:
{
"result": ["", {
"dataset": [{
"PLCode": "027",
"PLType": "P",
"PList": "BOSCH",
"PartNumber": "0986452041",
"Description": "FILTRO OLIO",
"F": "",
"DC": "F46",
"Price": "12,2",
"Picture": "",
"N": "",
"O": "027"
}, {
"PLCode": "484",
"PLType": "P",
"PList": "BRC",
"PartNumber": "BRF1101",
"Description": "FILTRO OLIO AVVITABILE",
"F": "",
"DC": " ",
"Price": "9,11",
"Picture": "",
"N": "",
"O": "484"
}]
}]
}
我尝试了不同的方式,例如:
public class Test {
private Result result;
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
}
public class Result {
private String errorDescription;
private List<Dataset> dataset;
public String getErrorDescription() {
return errorDescription;
}
public void setErrorDescription(String errorDescription) {
this.errorDescription = errorDescription;
}
public List<Dataset> getDataset() {
return dataset;
}
public void setDataset(List<Dataset> dataset) {
this.dataset = dataset;
}
}
当我尝试解析时: 测试测试=新测试(); test = objectMapper.readValue(message, Test.class);
我得到了下一个错误:
ERROR - RequestKromedaService.getKromedaAMReferences(142) : com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.beans.Result out of START_ARRAY token
你能帮帮我吗?
提前致谢
最佳答案
您的 Test
对象包含单个 Result
对象,但是 JSON 具有包含对象数组的 result
字段。数组中的项目是一个字符串,后跟一个看起来像 Result 对象的内容。
关于java - Java POJO中如何转换json字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35607916/