ajax解析后台回传String类型的json数据

后台代码:

@RequestMapping(value = "getServerDevice")
    @ResponseBody
    public String getServerDevice(
            HttpServletRequest request,
            HttpServletResponse response,
            @ModelAttribute ServerDevice inputData,
            ModelMap modelMap){
        String siteCode = inputData.getSiteCode();
        List<ServerDevice> serverDeviceList = serverDeviceService.getResultBySiteCode(siteCode);
        Gson gson = new Gson();
        String retString = gson.toJson(serverDeviceList);
        System.out.println(retString + "aaaaaa");
        return retString;
    }

json数据:

[{"deviceId":"5c4b907fb722413b801728f39eb5885e","siteCode":"1","siteName":"明尼苏达小区","localDeviceId":5,"localUploadDate":"Jun 24, 2019 4:00:00 PM","deviceAlarm":"null","deviceAlarmNum":0,"serverThemoList":[],"serverWaterList":[],"serverSmokeList":[],"serverHumidityList":[],"deviceNum":4,"deviceStatus":"OK","deviceAlarmLevel":1,"createdDate":"Jun 24, 2019 4:00:37 PM"}]aaaaaa

前台ajax代码:

$.ajax({
                type : "post",
                url : projectName + "/sensors/mobile/getServerDevice",
                data : inputData,
                dataType : "json",
                async : false,
                success: function (data)
                {
                    var obj = JSON.parse(data);
                    console.log(obj[0].deviceAlarmLevel + "   dddd");//根据实际业务需求,改为遍历读取即可。
                }
});


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值