jsonデータ変換異常:net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

2897 ワード

 1 //  Product       ,Product  mysql          
 2 ArrayList list = new ArrayList();
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;
	}
} 

リストを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