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 异常

时间: 2024-12-23 10:21:53

json数据转换异常:net.sf.json.JSONException: java.lang.reflect.InvocationTargetException的相关文章

json解析异常 - net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

注:在项目中, 我使用原生的ajax请求数据的时候, JSONObject没能帮我解析, 当却不给我报错, 我是在junit单元测试中测试的时候, 发现的.发现好多时候, 特别是通过ajax请求, 不给我们报错,很郁闷, 特别是ie, 有些问题, 得借助FireFox的返回结果分析. 当然, FireFox有时也没报错. 异常栈: net.sf.json.JSONException: java.lang.reflect.InvocationTargetException at net.sf.js

ajax请求json数据异常:nested exception is net.sf.json.JSONException: java.lang.reflect.InvocationTargetException] with root cause

ajax请求json数据异常:nested exception is net.sf.json.JSONException: java.lang.reflect.InvocationTargetException] with root cause 1.异常原因:所请求的json数据中包含java.util.date数据类型,但是在后台并没有将其格式转换 2.解决方法:添加工具类DateJsonValueProcessor import java.text.SimpleDateFormat; imp

含有Date类型属性的实体类转化为JSONArray时报net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

当我们通过session传递数据的时候我通常是: 直接在DAO里从数据库取出含Date类型的数据,而且通常不会将java.sql.Date转为java.util.Date. 这时候前台和后台都不会有任何问题,所以我们以为这样是正常的操作. 但是当我们用JSON传递数据的时候就会发现控制台会报一下错误信息: net.sf.json.JSONException: java.lang.reflect.InvocationTargetException 这时候我们可以再DAO里将java.sql.Dat

org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException异常解决

org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:246) org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178) org.apache.struts2.json.JSONWriter.p

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

private java.sql.Date startDate; public java.sql.Date getStartDate() { return startDate; } public void setStartDate(java.sql.Date startDate) { this.startDate = startDate; }

SpringBoot项目启动报错:java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

.   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Sprin

java.lang.reflect.invocationtargetexception

bout Sotirios-Efstathios Maneas Sotirios-Efstathios (Stathis) Maneas is a postgraduate student at the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. His main interests include distributed syste

session.createQuery()不执行和java.lang.reflect.InvocationTargetException

今天写SSH的工程的时候,执行到一个DAO中的Query query = session.createQuery(hql)的时候,没有成功执行,直接跳到了finally,然后前台报了500和java.lang.reflect.InvocationTargetException的错误. 代码如下: package dao; import java.util.List; import model.AccountInfo; import org.hibernate.HibernateException

HTTP Status 500 - java.lang.reflect.InvocationTargetException

type Exception report message java.lang.reflect.InvocationTargetException description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.RuntimeException: java.lang.reflect.InvocationTargetExc