JSON.stringify(obj)与后台

js:

var obj = new Object();
obj['cid'] = personId;

$.ajax({
                type:"post",
                data:{'data':JSON.stringify(obj)},
                url: "<%=basePath%>peabTopic/add",    
                success:function(result){
                    alert(result.msg);
                    if(result.flag){
                        resultId = result.id;
                        $("#excelBtn").css('display','block');
                        $("#pingceBtn").css('display','none');
                    }
                    artDialog.close();
                },
                error:function(){
                    alert("系统异常,请通知管理员!");
                }
            });
        }

 

后台:

public @ResponseBody Map add(HttpServletRequest request){

            String data = request.getParameter("data");
            JSONObject jsonO = JSONObject.fromObject(data);
            Iterator iter = jsonO.keySet().iterator();
            Map map = new HashMap();
            while(iter.hasNext()){
                String key = (String) iter.next();
                String value = jsonO.getString(key);
                map.put(key, value);
            }
            String cid1 = (String) map.get("cid");
            int cid = Integer.parseInt(cid1);
            String month1 = (String) map.get("month");
            int month = Integer.parseInt(month1);
            String projectCode = (String) map.get("projectCode");

}

 

你可能感兴趣的:(Interest,in,Java)