- JSON的格式
{ "dealerCode":"admin", "reqData":"[{ 'akhxm': '李四', 'azjhm': '421223199307021013', 'asjhm': '15212341234' }, { 'akhxm': '王五', 'azjhm': '421223199307021013', 'asjhm': '15212341256' }]'', "sequenceID":"SXJZSTANDRAD-20180717084856955311", "sign":"35142d30488a583b779bfdc0c2c210cf", "signMethod":"MD5" } |
- JSON的解析代码
//创建JSON数组对象 JSONArray outJsonArray = new JSONArray(); //获取map中的reqData String reqData = (String) bodymap.get("reqData"); //将reqData转化为JSON数组对象 JSONArray jsonArray = JSONArray.fromObject(reqData); Map map = new HashMap(); //遍历JSON数组 for (Object obj : jsonArray) { //将Object对象转化为JSON对象 JSONObject json = JSONObject.fromObject(obj); //遍历JSON键值对 for (Object str : json.keySet()) { map.put(str, json.get(str)); } //创建JSON对象 JSONObject outJson = new JSONObject(); //将值塞入JSON对象 outJson.put("aresp_code", "0000"); outJson.put("aresp_msg", "成功返回!"); //将JSON对象塞入JSON数组对象 outJsonArray.add(outJson); |