public String gettext(HttpServletRequest request,HttpServletResponse response){ List<xuanhuan_> xuanhuan = service.getxuanhuan(); JSONArray json = JSONArray.fromObject(xuanhuan); System.out.println(json);//在这里可以看到,json类型可以直接打印出来 return "/index"; }
打印结果:
[{"content":"","id":0,"name":"《测试》1","shijian":null},{"content":"","id":0,"name":"《测试》2","shijian":null},{"content":"","id":0,"name":"《测试》3","shijian":null},{"content":"","id":0,"name":"《测试》4","shijian":null},{"content":"","id":0,"name":"《测试》5","shijian":null},null,null,null]
下载是maven引入json的包:
<!-- json的包,不是项目自带的 --> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency>