关于FastJson bean中首字母大写与二层bean的问题。
2017-06-19 10:14
567 查看
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
输出是这个:{"Bean":{"AppSysID":"1"}}
=-=嗯就是这样了。。
@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"}}
=-=嗯就是这样了。。
相关文章推荐
- fastjson将bean转成字符串时首字母变小写问题
- 关于object转json 首字母大写问题
- Android请求网络数据,json解析-FastJson遇到的问题 首字母大写问题
- Json 关于首字母不能为大写的问题
- 关于fastjson的一个坑:输出json时,bean对象属性首字母默认被小写
- fastjson将bean转成字符串时key首字母变小写问题
- 关于写接口 FastJson 输出json结果集 大小写问题
- 解决com.alibaba.fastjson.JSON返回数据自动把首字母改为小写问题
- 关于数据序列化(5),定制FastJSON序列化(解决Java大Long类型js的Number接收丢失数据的问题,不序列化某些属性)
- 使用fastjson编辑全大写字段时遇到的问题
- FastJson bean序列化属性顺序问题
- 关于java 正则表达式 与 fastjson的兼容性问题
- FastJson bean序列化属性顺序问题
- java关于fastjson转成map后进行操作报错问题的坑
- 关于fastjson大小写转换问题的解决办法
- fastjson转换对象,属性首字母大小写的问题
- net.sf.ezmorph.bean.MorphDynaBean cannotbe cast to xxx 关于JSON对象解析List<XXX>在调用时出错问题
- Json 转Java对象时,遇到Key值首字母大写无法转换问题
- 关于fastjson的@JSONField注解的一些问题(详解)
- 关于json转换bean,Date为当前系统时间的问题