将集合转换成json对象时,去除不想要的字段

 

public void selectAllType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			CatService cs=new CatService();
			List types=cs.getType();
			System.out.println("_____"+types.size());
			
            //通过JsonConfig的对象,来去除,json数据中不要的字段
			JsonConfig cfg = new JsonConfig();
			cfg.setExcludes(new String[]{"Cars","Car","type","Type"});
			 
			//将集合转换成json
			JSONArray ja=JSONArray.fromObject(types,cfg);
			
			//将json响应给异步
			PrintWriter out=response.getWriter();
			out.print(ja.toString());
			out.flush();
			out.close();
			

		}

 

你可能感兴趣的:(将集合转换成json对象时,去除不想要的字段)