逐层解析请求json参数字符串【我】
import net.sf.json.JSONObject;
逐层解析请求json参数字符串:
InputStream inStream =null; BufferedReader br =null; String reJson=""; String rtJson=""; String tranId=""; //返回报文字段 String resultCode = "1"; String resultMsg = "失败"; try { httpRequest.setCharacterEncoding("UTF-8"); inStream = httpRequest.getInputStream(); String reqUrl= httpRequest.getRequestURI(); syslogger.info(reqUrl); String[] method = reqUrl.split("/", 0); Map headMap = this.getHeaderMap(httpRequest); Map params = this.getParameterMap(httpRequest); syslogger.info(params); br = new BufferedReader(new InputStreamReader(inStream,"UTF-8")); String str=br.readLine(); StringBuffer json = new StringBuffer(); while (str != null) { try { json.append(str); str = br.readLine(); } catch (Exception blExc) { System.out.println("请求参数获取出错------------str:"+str); throw new CommonRunException(blExc.getMessage(), blExc, ""); } } reJson=json.toString(); syslogger.info("resultlog 请求------------"+json); // String httpMethod = httpRequest.getMethod().toUpperCase(); System.out.println("resultlog 请求------------"+json); //调用相关的程序逻辑 tranId=RequestUtil.getMapValue(headMap,"X-CTG-Request-Id"); if("".equals(tranId)){ tranId=RequestUtil.getMapValue(headMap,"X-CTG-Request-ID"); } //调用实现类参数 String param = ""; try { //逐层解析报文获取请求参数 JSONObject jsobRst1 = JSONObject.fromObject(json.toString()); syslogger.info("jsobRst1 请求------------"+jsobRst1); String svcCont = jsobRst1.getString("svcCont"); JSONObject requestObject = JSONObject.fromObject(svcCont); param = requestObject.get("requestObject").toString(); param = jsobRst1.toString(); } catch (Exception e) { System.out.println("请求参数解析出错------------str:"+json); syslogger.info("解析报文出错 请求------------"+e); throw new Exception("解析报文出错 请求------------"+e); }