美文网首页
springmvc使用json格式的数据进行前后台交互

springmvc使用json格式的数据进行前后台交互

作者: 叶子23 | 来源:发表于2017-11-28 00:12 被阅读0次


    1.json格式字符串:

        String json= "{\"msg\":\"成功\",\"code\":100,\"content\":\"插入3条数据\"}";


    2.java对象:

            Result result = new Result();

            result.put("msg","成功");

            result.put("code",100);

            result.put("content","插入3条数据");

            JsonObject jsonObject = JsonObject.fromObject(result);

            response.setCharacterEncoding("utf-8");//响应字符集的编码格式               response.getWriter().print(jsonObject.toString());    


    3.Map:

            Map map=newHashMap();

            String json= "{\"msg\":\"成功\",\"code\":100,\"content\":"插入3条数据"}";

            map.put("json", json);

            returnjsonMap;    

    相关文章

      网友评论

          本文标题:springmvc使用json格式的数据进行前后台交互

          本文链接:https://www.haomeiwen.com/subject/swgjbxtx.html