将java对象转成json,方便前端处理数据 public class JsonUtil { public static String toJson(Object bean) { if (bean == null) return "null"; if (bean instanceof Collection || bean.getClass().isArray()) { return JSONArray.fromObject(bean).toString(); } return JSONObject.fromObject(bean).toString(); } }