将json数据格式的字符装装换成java对象(PO)

public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		 String s = request.getParameter("jsonDate");//ajax传递够来的json数据
		 response.setCharacterEncoding("utf-8");
         JSONObject jsonObj = JSONObject.fromObject(s);//将json数据的字符串转换为JSONObject对象		
         Userinfo u = (Userinfo)JSONObject.toBean(jsonObj,Userinfo.class);//json对象转换成PO
         boolean b = userService.update(u);
         PrintWriter pw = response.getWriter();
         if(b)
         {
         	pw.write("记录更新成功");
         }else
         {
        	 pw.write("记录更新失败");
         }
         pw.close();
	}

你可能感兴趣的:(java,Ajax,json)