ArrayList colorList=colorMapper.selectByAll();
HttpSession session=request.getSession();
//System.out.println(colorList.get(0).toString());
session.setAttribute(“colorList”, colorList);
//JSONArray jsonArray = JSONArray.fromObject(colorList);
response.getWriter().print(colorList.toString());
返回值
[com.openlab.bean.CommColor@2d73b4d, com.openlab.bean.CommColor@146e549e, com.openlab.bean.CommColor@42e16651, com.openlab.bean.CommColor@3d2f1c90, com.openlab.bean.CommColor@699452b, com.openlab.bean.CommColor@60b53bc2, com.openlab.bean.CommColor@292f0a6b]
CommSizeMapper sizeMapper=session1.getMapper(CommSizeMapper.class);
ArrayList sizeList=sizeMapper.selectByAll();
JSONArray sizeListArray=JSONArray.fromObject(sizeList);
response.getWriter().print(sizeListArray.toString());
session.setAttribute(“sizeList”, sizeListArray);
}
返回值
[{“sizeid”:1,“sizename”:“XL”,“specificationid”:0},{“sizeid”:2,“sizename”:“XXL”,“specificationid”:0},{“sizeid”:3,“sizename”:“XXXL”,“specificationid”:0},{“sizeid”:4,“sizename”:“L”,“specificationid”:0}]
由此可以得出,JSON可以对对象序列化 与 字符串进行传递