net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

原因一

执行:
JSONArray array = JSONArray.fromObject(this.users);

就会报以下错误:
net.sf.json.JSONException: Java.lang.reflect.InvocationTargetException

users是一个list集合

JSONArray array = JSONArray.fromObject(this.users.toArray()); 

原因二

因为bean里有Date字段,且从数据库里读出来的是java.sql.Date赋值给了java.util.Date,转化成JSONArray时出错;可以在从数据库读出Date 时直接写成:new java.util.Date(rs.getDate("date").getTime),这样就不会出错了;

public Date getBrithday() {
		
		System.out.println("brithday:"+brithday);

		System.out.println("brithday.getDate():"+brithday.getDate());

		System.out.println("brithday.getTime():"+brithday.getTime());

		System.out.println(" new java.util.Date(brithday.getTime()):"+new java.util.Date(brithday.getTime()));
		
		return new java.util.Date(brithday.getTime());
		//return brithday;
	}

输出为

brithday:1989-10-11
brithday.getDate():11
brithday.getTime():624038400000
new java.util.Date(brithday.getTime()):Wed Oct 11 00:00:00 CST 1989
jason格式

["brithday":{"date":11,"day":3,"hours":0,"minutes":0,"month":9,"seconds":0,"time":624038400000,"timezoneOffset":-480,"year":89}]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值