NutzCN Logo
问答 Json.fromJson不能正确解析json串
发布于 2538天前 作者 lambert 3006 次浏览 复制 上一个帖子 下一个帖子
标签:

大哥好,我这里有一串json,用在线的也能正常读出来,可是不能被正确的翻成类,您给看看,我用的是
Root r = Json.fromJson(Root.class, json); 原来没发现有这个问题呢

///待转json格式串
{
    "HEAD": {
        "TX_CD": "0101004",
        "CHAR_CODE": "GBK",
        "JRN_NO": "201706190134986614",
        "VER_CODE": "1.0",
        "MSG_CD": "MKM00000",
        "MSG_DAT": " 很好",
        "SIGN_MSG": "e05ce49c5489fab472462ef181d922e2",
        "ZF_TX_DT": "20170704",
        "ZF_TX_TM": "161547",
        "SIGN_MSG_US": "e05ce49c5489fab472462ef181d922e2"
    },
    "BODY": {
        "BAL": "100",
        "MBL_NO": "18610297435"
    }
}


转成的类:

public class Root
{
	private HEAD head;

	private BODY body;

	public HEAD getHead(){
		return this.head;
	}
	public void setHead(HEAD head){
		this.head = head;
	}

	public BODY getBody(){
		return this.body;
	}
	public void setBody(BODY body){
		this.body = body;
	}
}

public class BODY
{
	private String bal;

	private String mbl_no;

	public String getBal(){
		return this.bal;
	}
	public void setBal(String bal){
		this.bal = bal;
	}

	public String getMbl_no(){
		return this.mbl_no;
	}
	public void setMbl_no(String mbl_no){
		this.mbl_no = mbl_no;
	}
}

public class HEAD
{
	private String tx_cd;

	private String char_code;

	private String jrn_no;

	private String ver_code;

	private String msg_cd;

	private String msg_dat;

	private String sign_msg;

	private String zf_tx_dt;

	private String zf_tx_tm;

	private String sign_msg_us;

	public String getTx_cd(){
		return this.tx_cd;
	}
	public void setTx_cd(String tx_cd){
		this.tx_cd = tx_cd;
	}

	public String getChar_code(){
		return this.char_code;
	}
	public void setChar_code(String char_code){
		this.char_code = char_code;
	}

	public String getJrn_no(){
		return this.jrn_no;
	}
	public void setJrn_no(String jrn_no){
		this.jrn_no = jrn_no;
	}

	public String getVer_code(){
		return this.ver_code;
	}
	public void setVer_code(String ver_code){
		this.ver_code = ver_code;
	}

	public String getMsg_cd(){
		return this.msg_cd;
	}
	public void setMsg_cd(String msg_cd){
		this.msg_cd = msg_cd;
	}

	public String getMsg_dat(){
		return this.msg_dat;
	}
	public void setMsg_dat(String msg_dat){
		this.msg_dat = msg_dat;
	}

	public String getSign_msg(){
		return this.sign_msg;
	}
	public void setSign_msg(String sign_msg){
		this.sign_msg = sign_msg;
	}

	public String getZf_tx_dt(){
		return this.zf_tx_dt;
	}
	public void setZf_tx_dt(String zf_tx_dt){
		this.zf_tx_dt = zf_tx_dt;
	}

	public String getZf_tx_tm(){
		return this.zf_tx_tm;
	}
	public void setZf_tx_tm(String zf_tx_tm){
		this.zf_tx_tm = zf_tx_tm;
	}

	public String getSign_msg_us(){
		return this.sign_msg_us;
	}
	public void setSign_msg_us(String sign_msg_us){
		this.sign_msg_us = sign_msg_us;
	}
}
5 回复

你的key全是大写啊

结贴吧,是因为转的时候,没有严格按照json里的大小写来定义实体,所以,转不了

你可以加@JsonField

对,是的,谢谢大神,我也是刚反应过来

JsonField可以设置name的

添加回复
请先登陆
回到顶部