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);

你可能感兴趣的:(技术)