<%@ page language="java" contentType="text/ html; jeu de caractères=UTF-8"
pageEncoding="UTF-8"%>
Insérer le titre ici
url="getUsers.jsp" toolbar= "#toolbar" rownumbers="true" fitColumns="true" singleSelect="true"> Prénom Nom Télé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"%> Insérer le titre ici <% //String json = "{"firstname":"firstname","lastname":"lastname","phone":123456,"email":"281446883@qq.com"} " ; Liste> list = new ArrayList>(); Carte user1 = new HashMap(); user1.put("firstname", "name1"); user1.put("lastname", "name2"); user1.put("téléphone", "1234"); user1.put("email", "281446888@qq.com"); list.add(user1); Carte user2 = new HashMap(); user2.put("firstname", "name2"); user2.put("lastname", "name4"); user2.put("téléphone", "1234"); user2.put("email", "281446888@qq.com"); list.add(user2); JSONArray jsonArray = JSONArray.fromObject(list); System.out.println(jsonArray.toString()); Carte map = new HashMap(); map.put("total", 1); map.put("rows", jsonArray); ObjectMapper objMap = new ObjectMapper(); objMap.writeValue(response.getWriter(), map); //System.out.println(json); %>
效果: