问题描述
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {Map<String, Object> map = new HashMap<String, Object>();ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();for(int i=0;i<3;i++){ HashMap<String,Object> jsonMap = new HashMap<String, Object>();jsonMap.put("id", i);jsonMap.put("username", "王三");jsonMap.put("password", "123");jsonMap.put("age", 20+i);list.add(jsonMap);}map.put("aa", list);System.out.println(map);JSONObject.fromObject(map);PrintWriter out = response.getWriter();out.print(map);out.flush();out.close();}$(document).ready(function(){$.ajax({url:'/JGrid/servlet/JGridServlet',type:'post',dataType:'json',success:function(data){alert('成功!');alert(data);},error:function(){alert('内部错误!');}});});引用
解决方案
String json="{"status":0,"data":0}";json的个格式应该是这样的
解决方案二:
out.print(map); 打印的是map
解决方案三:
ajax 改成text试试