关于FastJson bean中首字母大写与二层bean的问题。

前端之家收集整理的这篇文章主要介绍了关于FastJson bean中首字母大写与二层bean的问题。前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


1.首字母大写只要在bean前面get上加上

  @JsonProperty(value = "Name")  
即可。

例如

	private String AppSysID;//APP版本号
        @JSONField(name = "AppSysID")
	public String getAppSysID() {
		return AppSysID;
	}
	public void setAppSysID(String AppSysID) {
		this.AppSysID = AppSysID;
	}


2.如果bean外面需要包一层。例如

{"Bean":{ "AppSysID":"10.1" }}

则bean类为

{"Bean":{ "AppSysID":"10.1" }}

public class DevInfo {
	public Bean Bean;  
        public class  Bean {  
		private String AppSysID;//APP版本号
                @JSONField(name = "AppSysID")
		public String getAppSysID() {
			return AppSysID;
		}
		public void setAppSysID(String appSysID) {
			AppSysID = appSysID;
		}

        }
 
        @JSONField(name = "Bean")
	public Bean  getBean () {
		return Bean ;
	}

	public void setBean (Bean  getBean ) {
		this.Bean  = getBean ;
	}

}

然后转成JSON
 
DevInfo devinfo = new DevInfo();
Bean devSend = devinfo.new Bean();
devSend.setAppSysID("1");
devinfo.setBean(devSend);
JSONObject devIDJSONObj = JSONObject.parSEObject(JSON.toJSONString(devinfo));
String json = devIDJSONObj.toJSONString();
System.out.println(json);
输出是这个:{"Bean":{"AppSysID":"1"}} =-=嗯就是这样了。。 原文链接:https://www.f2er.com/json/288872.html

猜你在找的Json相关文章