裸版json是fastJson的底层实现原理

public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		UsersDAO dao = new UsersDAO();
		
		List lt = dao.findAll();
		//把数据库的数据变成json以后存储在服务器物理地址,让客户来访问
		File file = new File("F://Tomcat//apache-tomcat-8.5.31//webapps//TestAndroid//Users.json");
		file.createNewFile();
		//用一个stringBuffer来存储着每次转换完成的string
		StringBuffer sb = new StringBuffer();
		sb.append("[");
		int i= 0;
		int size = lt.size();
		for (Users user : lt) {
			i++;
			sb.append("{");
			sb.append("\"id\":\""+user.getId()+"\",");
			sb.append("\"name\":\""+user.getName()+"\",");
			sb.append("\"age\":\""+user.getAge()+"\",");
			sb.append("\"tupian\":\""+user.getTupian()+"\",");
			sb.append("\"sex\":\""+user.getSex()+"\",");
			sb.append("\"favorite\":\""+user.getFavorite()+"\",");
			sb.append("\"pass\":\""+user.getPass()+"\"");
			sb.append("}");
			if (i

当然这肯定不是fastjson的全部底层,还需通过反射来了解传过来的是什么对象

你可能感兴趣的:(裸版json是fastJson的底层实现原理)