开发者社区 问答 正文

extjs表单提交后,数据打印后不是json格式

前台数据{ id:'user_update', text: '编辑', maxWidth:55, handler:function(){ var user_form = this.up('form'); if(user_form.getForm().isValid()){ user_form.getForm().submit({ // url: 'updateUserServlet', url:'MyJsp.jsp',

                            method:'post', 
                            
                            submitEmptyText: false, 
                            waitTitle:'请等待', 
                            waitMsg: '正在编辑用户...', 
                            params : { 
                                id : userid, 
                                userName : userName, 
                                userPermiss : userPermiss, 
                                description : description, 
                                userPasswd : userPasswd 
                            }, 
                            
                            success:function(form,action){ 
                                var response = Ext.decode(action.response.responseText); 
                                Ext.Msg.alert('提示', response.msg); 
                                userStore.load(); 
                            }, 
                            failure:function(form,action){ 
                                Ext.Msg.alert('提示', '编辑用户失败!'); 
                            } 
                        }); 
                    }else{ 
                        Ext.Msg.alert('提示', '数据验证失败!'); 
                    } 
                } 
            } 

后台代码:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.BufferedReader" %> <%@ page import="net.sf.json.*" %> <% BufferedReader in=request.getReader(); StringBuffer jsonStr=new StringBuffer(); String str=""; while((str=in.readLine())!=null){ jsonStr.append(str); } JSONObject jsonObj= JSONObject.fromObject(jsonStr.toString()); String name= jsonObj.getString("userName");

String msg=""; out.print("asdf"); out.print(name);

%> 服务器报错为:严重: Servlet.service() for servlet jsp threw exception net.sf.json.JSONException: A JSONObject text must begin with '{' at character 1 of id=3&userName=yy&userPermiss=3&description=&userPasswd=usd1111 经过打印后,得到的数据为id=3&userName=yy&userPermiss=3&description=&userPasswd=usd1111不是json格式,请问哪里有问题??

展开
收起
长安归故里. 2020-01-07 13:28:23 1038 分享 版权
1 条回答
写回答
取消 提交回答
  • 用最简单的方式啊,你的代码太复杂了

    Java代码 收藏代码

    Enumeration<String> em=request.getParameterNames();  
    String pm="";  
    JSONObject jsonObj = new JSONObject();  
    while(em.hasMoreElements()){  
        pm = em.nextElement();  
        jsonObj.put(pm, request.getParameter(pm));  
    }  
      
    String name= jsonObj.getString("userName");
    
    2020-01-07 13:28:49
    赞同 展开评论