后台
Map<String,Integer> map = new HashMap<>();
map.put("你好1", 1);map.put("你好2", 2);
map.put("你好3", 3);
map.put("你好4", 4);
map.put("你好5", 5);
Gson gson = new Gson();
String json = URLEncoder.encode(gson.toJson(map),"utf-8");
out.print(json);
前台
success:function(data){
data = decodeURIComponent(data);
eval("var js="+data);
for(var i in js){
$(‘table‘).append("<tr><td>"+i+"</td><td>"+js[i]+"</td></tr>");
}
i为key的值
js[i]为key对应的值