About the JSON front end cannot be parsed

How to pass the tip of json have not read the contents, but there is direct printing data content
closer look
Goodfellas

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

Although JSON conversion was created and used,
but forgot to declare the transmission format

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

Which is this sentence

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

The complete is

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

When docking, remember to specify the return data mode json

Guess you like

Origin blog.csdn.net/m0_49194578/article/details/112409619