1. 程式人生 > >JSON轉物件(實體類物件)

JSON轉物件(實體類物件)

1、建立物件

import java.io.Serializable;import com.alibaba.fastjson.annotation.JSONField;public class PushMsgContent implements Serializable{	/**	 * 	 */	private static final long serialVersionUID = 1L;			private String amt1;//	本金  amt1	private String amt2;//	放款金額    amt2	private String amt3;//	應還本利合計為  amt3			@JSONField(name = "amt1")//對應json中的key值	public String getAmt1() {		return amt1;	}	public void setAmt1(String amt1) {		this.amt1 = amt1;	}	@JSONField(name = "amt2")	public String getAmt2() {		return amt2;	}	public void setAmt2(String amt2) {		this.amt2 = amt2;	}	@JSONField(name = "amt3")	public String getAmt3() {		return amt3;	}	public void setAmt3(String amt3) {		this.amt3 = amt3;	}}

2、使用alibabajson把json字串轉物件import com.alibaba.fastjson.JSON;

String msgContent = “{json字串}”; PushMsgContent pushMsgContent = JSON.parseObject(msgContent,PushMsgContent.class);

(function(){ function setArticleH(btnReadmore,posi){ var winH = $(window).height(); var articleBox = $(“div.article_content”); var artH = articleBox.height(); if(artH > winH*posi){ articleBox.css({ ‘height’:winH*posi+‘px’, ‘overflow’:‘hidden’ }) btnReadmore.click(function(){ articleBox.removeAttr(“style”); $(this).parent().remove(); }) }else{ btnReadmore.parent().remove(); } } var btnReadmore = $("#btn-readmore"); if(btnReadmore.length>0){ if(currentUserName){ setArticleH(btnReadmore,3); }else{ setArticleH(btnReadmore,1.2); } } })()