欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Json转换利器Gson之实例一-简单对象转化和带泛型的List转化

程序员文章站 2022-04-04 12:50:56
...
List<EhomepayReviewRecord> reviewList = new ArrayList<EhomepayReviewRecord>();
		EhomepayReviewRecord review  = new EhomepayReviewRecord();
		review.setId(1);
		review.setAuditResult("1");
		reviewList.add(review);
		review.setId(2);
		review.setAuditResult("2");
		reviewList.add(review);
		
		Gson gson = new Gson();
	    String lastReviewListStr = gson.toJson(reviewList);
	    System.out.println(lastReviewListStr);
	    List<EhomepayReviewRecord> reviewListyy = new ArrayList<EhomepayReviewRecord>();
	   
	    List<EhomepayReviewRecord> retList = gson.fromJson(lastReviewListStr,  
                new TypeToken<List<EhomepayReviewRecord>>() {  
                }.getType());  
        for (EhomepayReviewRecord stu : retList) {  
            System.out.println(stu);  
        }