关于FastJson bean中首字母大写与二层bean的问题。
发布时间:2020-12-16 18:46:32 所属栏目:百科 来源:网络整理
导读:1.首字母大写只要在bean前面get上加上 @JsonProperty(value = "Name") 即可。 例如 private String AppSysID;//APP版本号 @JSONField(name = "AppSysID")public String getAppSysID() {return AppSysID;}public void setAppSysID(String AppSysID) {this.App
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"}} =-=嗯就是这样了。。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- React Native入门——布局实践:开发京东客户端首页(二)T
- 选择排序法
- Cocos2d-x中 发起http请求
- Unable to resolve resource bundle “CairngormMessages”
- fouc Flash of Unstyled Content)
- 设计模式—七大原则
- ruby-on-rails – RubyInstaller 2.2.1和Rails – Rake无法
- ruby-on-rails – 如何在Rails中的date_select中使用空白和
- 如何在swift中覆盖layerClass
- ruby-on-rails – Ruby / Rails同步作业管理器