fastjson SerializerFeature详解: fastjson把对象转化成json避免$ref:

toJSONString(obj):对象属性值相同显示fail用:toJSONString(obj,SerializerFeature.DisableCircularReferenceDetect)


fastJson.jar API

阿里jar

参考:

===问题效果:


===问题原因:

API  toJSONString(obj)自身问题。

参考:

fastjson SerializerFeature详解:


http://blog.csdn.net/u010246789/article/details/52539576

fastjson把对象转化成json避免$ref:

http://blog.csdn.net/u010246789/article/details/52538953


====问题解决:===禁用 对象循环引用。。

	@Action("CourierAction_findByPage")
	public void  findByPage(){
		System.out.println("=====page...:"+page);
		//Pageable pageAble = new PageRequest(page, rows);
		Pageable pageAble = new PageRequest(page-1, rows);
		 Page<Courier> pageData = service.findAll(pageAble );
		 long total = pageData.getTotalElements();
		 List<Courier> list = pageData.getContent();
		 
		 HashMap<String, Object> map = new HashMap<>();
		 map.put("total", total);
		 map.put("rows", list);
		//map转json
		// String json = (String) JSON.toJSON(map);//==######==报错:pageSize必须大于0
		  //String json =  JSON.toJSON(map).toString();//==######==报错:pageSize必须大于0
		 //String json =  JSON.toJSONString(map);//==######==报错:值相同的standard对象属性【对象重用】,页面显示不出来
		 //===解决:
		 String json =  JSON.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect);//SerializerFeature是个枚举类型。消除循环引用
		 System.out.println("json:"+json);
		 
		 HttpServletResponse response = ServletActionContext.getResponse();
		 response.setContentType("application/json;charset=utf-8");
		 try {
			response.getWriter().write(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


===========================


猜你喜欢

转载自blog.csdn.net/qq_20597149/article/details/78376713