ldl
ldl
  • 发布:2016-01-19 15:47
  • 更新:2016-01-20 15:45
  • 阅读:5420

ajax请求java后台,返回的json数据,为何取不到值呢

分类:MUI

html页面代码:

mui.ajax({  
                    type: "get",  
                    url: "http://192.168.0.101:8081/fzyzjk/business/app/ajaxLogin.html",  
                    async: true,  
                    data: {  
                        uphone: uphone,  
                        upassword: upwd  
                    },  
                    dataType: "json",  
                    timeout: 1000,  
                    success: function(data) {  
                        //[{"alreadyLogined":false,"defaultPassword":false,"loginSuccess":false,"permissionEntity":null,"result":0,"user":{}}]  

                        var jsdata=JSON.stringify(data);  
                        var ret=jsdata.status;  
                        console.log(ret);

以下省略
===================================================================
返回的json数据:

[{"alreadyLogined":false,"defaultPassword":false,"loginSuccess":false,"permissionEntity":null,"result":0,"user":{}}]  
var jsdata=JSON.stringify(data);  
var ret=jsdata.status;(这里ret没取到,控制台输出为:undefined)

这是为何呢?谢谢了。
================以下是java后台======================================

 String uphone = request.getParameter("uphone");  
            String upassword = request.getParameter("upassword");  

            Map userMap = appInterfaceService.getUserByLoginName(uphone);  
            Map retMap=new HashMap();  
            retMap.put("user", userMap);  
            retMap.put("status", "3");  
            //用户名不存在  
            if (userMap == null || userMap.isEmpty()) {  
                retMap.put("status",""+(LoginEntity.Login_Result_UserNameNotExists));  
            }else{  
                //用户名或密码错误  
                if (!EqualUtil.isStringEqual(userMap.get("PASSWORD"),appInterfaceService.getEncodedPassword(upassword))) {  
                    retMap.put("status",""+(LoginEntity.Login_Result_PassowrdError)+"");  
                }  
                //用户被禁用  
                if (EqualUtil.isStringEqual(userMap.get("ZT"), "2")) {  
                    retMap.put("status",""+(LoginEntity.Login_Result_LoginForbid)+"");  
                }  
            }  
            System.out.print( JsonUtil.obj2Json(retMap));  
            WebUtil.write(response, JsonUtil.obj2Json(retMap));
2016-01-19 15:47 负责人:无 分享
已邀请:
DCloud_UNI_FXY

DCloud_UNI_FXY

直接打印的你的jsdata,看你贴的

返回的是[{"alreadyLogined":false,"defaultPassword":false,"loginSuccess":false,"permissionEntity":null,"result":0,"user":{}}] 
这是一个数组,怎么会
var jsdata=JSON.stringify(data);
var ret=jsdata.status;
这是个什么意思。stringify是把json对象格式化成字符串,你怎么会又用字符串去取status?

  • yomz

    你好,picker的demo中,选择后输出的json数组如何不带双引号呢?求解谢谢!userResult.innerText = JSON.stringify(items[0].text);

    2016-03-14 23:26

  • yomz

    加了parse解决了,谢谢!

    2016-03-14 23:34

该问题目前已经被锁定, 无法添加新回复