我如何轉換的JSON字符串是這樣的:轉換的LinkedHashMap <字符串,MyClass的>到Java對象
{ "summary": {
"totalMR":4.599000000000903E12,
"totalMA":1.9174920000386694E11,
"totalQA":5.1111111181E9,
"totalQR":1.000020666115264E11
},
"result": [{},{}],
"success":"true",
"total":49
}
Java對象。我經歷了許多類似的帖子並實現了構造函數,但找不到解釋爲什麼我無法反序列化JSON的正確解釋。
我做錯了什麼?
我的班級:
public class expResponse {
private String success;
private String total;
private ArrayList<LinkedHashMap<String,Object>> result;
private LinkedHashMap<String,SummaryResponse> summary;
// Constructor: public expResponse(){}
// Getter and Setter
}
public class SummaryResponse {
private Float totalQR;
private Float totalQA;
private Float totalMR;
private Float totalMA;
public SummaryResponse(){}
// Setter and Getter
}
我的代碼:
private expResponse processResult(String result) throws IOException{
ObjectMapper objectMapper = new ObjectMapper();
expResponse expResponseObj =
objectMapper.readValue(result, expResponse.class);
return expResponseObj;
您正在使用哪個JSON庫? – Nayuki
@Nayuki Jackson – Jammy
你是什麼意思「無法反序列化JSON」?你是否遇到異常?缺失數據?你的電腦是否冒出藍煙? – dimo414