JSONArray json=JSONArray.fromObject(list);报错

如上,每次执行到JSONArray json=JSONArray.fromObject(sites);这一句就报这样一个错误,实在是搞不懂啊,以前就是这么用的也没出错。
项目用的ssh,请求是ajax请求
导入的包有
commons-beanutils-1.8.0.jar
commons-collections.jar
commons-lang.jar
commons-logging.jar
ezmorph-1.0.6.jar
json-lib-2.2.3-jdk15.jar
struts2-json-plugin-2.1.8.jar

debug 一下,看看 sites拿到数据没有,BikeSite是否有自包含?

你可以把 json转换这个 try catch一下,看看转换出错的原因。

追问

拿到了,5条数据,没有空数据,BikeSite是一个简单的封装类,没有包含关系

好像是有个日期类型的属性的问题,我试试

追答

BikeSite中有类型为Date的属性? 这个Date用的是java.sql.Date? 你看看这个类里,有一个getHours方法,它是不支持的。看看能不能改为 java.util.Date,或不用这个方法。

// json-lib默认不支持java.sql.Date的序列化,要序列化自己的类,实现一个BeanProcessor处理即可
JsDateJsonBeanProcessor beanProcessor = new JsDateJsonBeanProcessor();
java.sql.Date d = new java.sql.Date(System.currentTimeMillis());

// 直接序列化
JsonConfig config = new JsonConfig();
JSONObject json = beanProcessor.processBean(d, config);
System.out.println(json.toString());

// 序列化含java.sql.Date作为属性值的bean
HashMap m = new HashMap();
m.put("date", d);
config.registerJsonBeanProcessor(java.sql.Date.class, beanProcessor);
json = JSONObject.fromObject(m, config);
System.out.println(json.toString());

温馨提示:答案为网友推荐,仅供参考