json数据转换异常:net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

 1 //存储Product对象的集合是从,Product是从mysql数据库中查询并添加的
 2 ArrayList<Product> list = new ArrayList<Product>();
3 4 //设置响应对象编码 5 response.setCharacterEncoding("utf-8"); 6 response.setContentType("text/html;charset=utf-8"); 7 8 //将list集合转换成json格式 9 JSONArray json = JSONArray.fromObject(list); 10 11 //将json写出浏览器 12 response.getWriter().print(json);


Product类

public class Product implements Serializable{

	private static final long serialVersionUID = -992811686857962266L;
	
	private String pid; //商品编号
	private String pname; //商品名称
	private Double market_price; //市场价格
	private Double shop_price; //商城价格
	
	private String pimage; //商品图片
	private Date pdate;  //上架日期
	private Integer is_hot = 0; //是否热门商品, 1表示热门, 0表示不热门
	private String pdesc; //商品描述
	
	private Integer pflag; //表示是否下架, 1表示下架, 0表示不下架
	private Category category; //商品所属的分类对象
	
	public Product() {}
	
	public Product(String pid, String pname, Double market_price, Double shop_price, String pimage, Date pdate,
			Integer is_hot, String pdesc, Integer pflag, Category category) {
		this.pid = pid;
		this.pname = pname;
		this.market_price = market_price;
		this.shop_price = shop_price;
		this.pimage = pimage;
		this.pdate = pdate;
		this.is_hot = is_hot;
		this.pdesc = pdesc;
		this.pflag = pflag;
		this.category = category;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public String getPname() {
		return pname;
	}

	public void setPname(String pname) {
		this.pname = pname;
	}

	public Double getMarket_price() {
		return market_price;
	}

	public void setMarket_price(Double market_price) {
		this.market_price = market_price;
	}

	public Double getShop_price() {
		return shop_price;
	}

	public void setShop_price(Double shop_price) {
		this.shop_price = shop_price;
	}

	public String getPimage() {
		return pimage;
	}

	public void setPimage(String pimage) {
		this.pimage = pimage;
	}

	public Date getPdate() {
		return pdate;
	}

	public void setPdate(Date pdate) {
		this.pdate = pdate;
	}

	public Integer getIs_hot() {
		return is_hot;
	}

	public void setIs_hot(Integer is_hot) {
		this.is_hot = is_hot;
	}

	public String getPdesc() {
		return pdesc;
	}

	public void setPdesc(String pdesc) {
		this.pdesc = pdesc;
	}

	public Integer getPflag() {
		return pflag;
	}

	public void setPflag(Integer pflag) {
		this.pflag = pflag;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}
} 

在将list转换成JSON格式的时候,从数据库里读出来的是java.sql.Date赋值给了java.util.Date,转化成JSONArray时出错

就会出现 et.sf.json.JSONException: java.lang.reflect.InvocationTargetException 异常

 

转载于:https://www.cnblogs.com/guo-rong/p/7535000.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值