json解析时报错:
03-22 19:59:33.356: W/System.err(8461): com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "approvalStatus" (class com.iris.live_demo.bean.ApprovalReplyInfo), not marked as ignorable (15 known properties: "approvalstatuscn", "usernamecn", "quotedpricecodeorvin", "transactioncode", "flag", "transcation_code", "approvalstatus", "username", "transcation_status", "type", "id", "processtime", "remark", "step", "permit"])
这种问题真的很狗血,搞半天。总结:这种数据类型不能直接解析为我们所需要的集合类型。
json格式:
{
"result": "true",
"message": null,
"pageData": {
"total": 3,
"data": [
{
"approvalStatus": "0",
"permit": "ZSJ",
"step": "step1",
"remark": "",
"id": 23185,
"type": 8,
"userName": "daer@lsh.com",
"approvalStatusCn": "待批复",
"userNameCn": "大二",
"processTime": "2017-03-17 18:30:36"
},
{
"approvalStatus": "0",
"permit": "ZSJ",
"step": "step2",
"remark": "",
"id": 23186,
"type": 8,
"userName": "dasan@lsh.com",
"approvalStatusCn": "待批复",
"userNameCn": "大三",
"processTime": "2017-03-17 18:30:36"
},
{
"approvalStatus": "0",
"permit": "ZSJ",
"step": "step3",
"remark": "",
"id": 23187,
"type": 8,
"userName": "dayi@lsh.com",
"approvalStatusCn": "待批复",
"userNameCn": "大一",
"processTime": "2017-03-17 18:30:36"
}
]
}
}
所以就手动解析:
if(null!=mReplyList){
mReplyList.clear();
}
String msgStr = (String) msg.obj;
try {
JSONObject jsonObject = new JSONObject(msgStr);
String isTrue = jsonObject.getString("result");
if("true".equals(isTrue)){
JSONObject jsonObj = jsonObject.getJSONObject("pageData");
JSONArray jsonArray = jsonObj.getJSONArray("data");
for(int i=0; i<jsonArray.length(); i++){
JSONObject jsonObject2 = (JSONObject)jsonArray.opt(i);
ApprovalReplyInfo replyInfo = new ApprovalReplyInfo();
replyInfo.setApprovalStatus(jsonObject2.getString("approvalStatus"));
replyInfo.setPermit(jsonObject2.getString("permit"));
replyInfo.setStep(jsonObject2.getString("step"));
replyInfo.setRemark(jsonObject2.getString("remark"));
replyInfo.setId(jsonObject2.getString("id"));
replyInfo.setType(jsonObject2.getString("type"));
replyInfo.setUserName(jsonObject2.getString("userName"));
replyInfo.setApprovalStatusCn(jsonObject2.getString("approvalStatusCn"));
replyInfo.setUserNameCN(jsonObject2.getString("userNameCn"));
replyInfo.setProcessTime(jsonObject2.getString("processTime"));
mReplyList.add(replyInfo);
}
}
} catch (Exception e) {
e.printStackTrace();
}