调整异常内解析json的方法,捕捉异常,并设置字段的默认值

This commit is contained in:
wangxin
2018-06-08 17:48:21 +08:00
parent 15ce519368
commit c9dc82f885
4 changed files with 27 additions and 44 deletions

View File

@@ -8,7 +8,7 @@
*/
package com.nis.domain;
import com.google.gson.JsonObject;
import org.apache.commons.lang.StringUtils;
import net.sf.json.JSONObject;
@@ -20,23 +20,29 @@ import net.sf.json.JSONObject;
* @version V1.0
*/
public class RestfulResult {
private Integer status;
private Integer businessCode;
private String reason;
private String msg;
private String traceCode;
private String fromuri;
private Integer status=0;
private Integer businessCode=0;
private String reason="";
private String msg="";
private String traceCode="";
private String fromuri="";
public RestfulResult(){
}
public RestfulResult(String content){
JSONObject resObject = JSONObject.fromObject(content) ;
this.status=resObject.getInt("status");
this.businessCode=resObject.getInt("businessCode");
this.reason=resObject.getString("reason");
this.msg=resObject.getString("msg");
this.traceCode=resObject.getString("traceCode");
this.fromuri=resObject.getString("fromuri");
try{
if(StringUtils.isNotBlank(content)){
JSONObject resObject = JSONObject.fromObject(content) ;
this.status=resObject.getInt("status");
this.businessCode=resObject.getInt("businessCode");
this.reason=resObject.getString("reason");
this.msg=resObject.getString("msg");
this.traceCode=resObject.getString("traceCode");
this.fromuri=resObject.getString("fromuri");
}
}catch (Exception e) {
// TODO: handle exception
}
}
/**
* status