<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Insert title here url="getUsers.jsp" toolbar="#toolbar" rownumbers="true" fitColumns="true" singleSelect="true"> First Name Last Name Phone Email
<%@page import="net.sf.json.JSONArray"%> <%@page import="java.util.*"%> <%@page import="org.codehaus.jackson.map.ObjectMapper"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
Insert title here <% //String json = "{"firstname":"firstname","lastname":"lastname","phone":123456,"email":"281446883@qq.com"}"; List> list = new ArrayList>(); Map user1 = new HashMap(); user1.put("firstname", "name1"); user1.put("lastname", "name2"); user1.put("phone", "1234"); user1.put("email", "281446888@qq.com"); list.add(user1); Map user2 = new HashMap(); user2.put("firstname", "name2"); user2.put("lastname", "name4"); user2.put("phone", "1234"); user2.put("email", "281446888@qq.com"); list.add(user2); JSONArray jsonArray = JSONArray.fromObject(list); System.out.println(jsonArray.toString()); Map map = new HashMap(); map.put("total", 1); map.put("rows", jsonArray); ObjectMapper objMap = new ObjectMapper(); objMap.writeValue(response.getWriter(), map); //System.out.println(json); %>
效果: