关于JSON前端无法解析

传给前端的json怎么都读取不出内容,但是直接打印data却有内容
定睛一看
好家伙

login.html:76 {"flag":false,"data":null,"errorMsg":"登录失败检查账号密码"}

虽然创建了JSON转换,也用了
但是却忘记声明传输格式

resultInfo.setFlag(false);
            resultInfo.setErrorMsg("登录失败检查账号密码");
            ObjectMapper objectMapper = new ObjectMapper();
            json = objectMapper.writeValueAsString(resultInfo);
            resp.getWriter().write(json);

也就是这句

resp.setContentType("application/json;utf-8");

完整的是

resultInfo.setFlag(false);
            resultInfo.setErrorMsg("登录失败检查账号密码");
            ObjectMapper objectMapper = new ObjectMapper();
            json = objectMapper.writeValueAsString(resultInfo);
            resp.setContentType("application/json;utf-8");
            resp.getWriter().write(json);

在对接时千万记得指定返回数据模式json

猜你喜欢

转载自blog.csdn.net/m0_49194578/article/details/112409619
今日推荐