HashMap转换成json实例
来源:互联网 发布:菊花插件数据下载 编辑:程序博客网 时间:2024/06/07 03:19
@1创建的Account类:
public class Account implements Serializable{/** * userId:用户id * userName:用户名称 * status:用户状态 * orgUUID:用户所属HR系统部门主键 * mobile:手机号码 * email:电子邮件 */private static final long serialVersionUID = 1L;private String userId;private String userName;private String status;private String orgUUID;private String mobile;private String email;}
@2HashMap转换成json方法
public JSONObject resposeJson(){JSONObject allJson = new JSONObject();HashMap<String, Object> hashMap = new HashMap<String, Object>();hashMap.put("SERVICE_ID", "120030002");hashMap.put("SCENE_ID", "120030002");hashMap.put("SOURCE_TYPE", "120030002");hashMap.put("PRVD_SYS_ID", "120030002");hashMap.put("RUN_DATE", "120030002");hashMap.put("TRAN_DATE", "120030002");hashMap.put("TRAN_TIMESTAMP", "120030002");hashMap.put("SEQ_NO", "120030002");hashMap.put("REFERENCE", "120030002");hashMap.put("RET_STATUS", "120030002");HashMap<String, String> hashMap2 = new HashMap<String, String>();hashMap2.put("RET_CODE", "000000");hashMap2.put("RET_MSG", "success");hashMap.put("RET", hashMap2);HashMap<String, Object> hashMap3 = new HashMap<String, Object>();Account account = new Account();account.setUserId("101");account.setUserName("cheney");account.setEmail("89@qq.com");account.setMobile("133113234");account.setOrgUUID("水果部门");account.setStatus("e");Account account2 = new Account();account2.setUserId("102");account2.setUserName("cheney1993");account2.setEmail("160@qq.com");account2.setMobile("13631223892");account2.setOrgUUID("菜鸡部门");account2.setStatus("e");List<Account> listAccounts = new ArrayList<Account>();listAccounts.add(account);listAccounts.add(account2);hashMap3.put("account", listAccounts);hashMap3.put("reponseJson", "test");allJson.put("SYS_HEAD", hashMap);allJson.put("BODY", hashMap3);return allJson;}
@3转换后的json格式化结果显示如下:
{ "SYS_HEAD": { "SOURCE_TYPE": "120030002", "RET": { "RET_MSG": "success", "RET_CODE": "000000" }, "REFERENCE": "120030002", "TRAN_TIMESTAMP": "120030002", "RUN_DATE": "120030002", "SCENE_ID": "120030002", "RET_STATUS": "120030002", "SERVICE_ID": "120030002", "PRVD_SYS_ID": "120030002", "TRAN_DATE": "120030002", "SEQ_NO": "120030002" }, "BODY": { "account": [ { "email": "89@qq.com", "mobile": "133113234", "orgUUID": "水果部门", "status": "e", "userId": "101", "userName": "cheney" }, { "email": "160@qq.com", "mobile": "13631223892", "orgUUID": "菜鸡部门", "status": "e", "userId": "102", "userName": "cheney1993" } ], "reponseJson": "test" }}
阅读全文
0 0
- HashMap转换成json实例
- 把hashMap转换成json
- HashMap转换成Json格式
- hashmap转换成json格式
- Springmvc ajax-json提交 转换成List<HashMap>
- json数据转换实例
- javascript中将json格式字符串转换成json对象实例
- 关于json字符串转换成json对象、HashMap和实体类的操作
- 利用Gson转换Json实例
- Json转换利器Gson实例
- 关于list转换成json报错和小实例
- 一种将list转换成hashmap的笨办法 其实是将json类型数据转换成键值对
- java中JSON将数组对象转换成JSON字符串输出实例
- 将JsonObject转换成HashMap
- 将JsonObject转换成HashMap
- json实例及各种形态的转换
- hashmap 实例
- JSON总结- JSON与JAVA的数据转换实例
- spring mvc
- java中嵌套接口
- 【C语言】三子棋游戏
- fuzhuo----
- NOI题解(1.8编程基础之多维数组)(待补全)
- HashMap转换成json实例
- Java中的快捷键大全
- 使用字符串分割出来每一位数字
- Veritas Cluster for linux修改主机名
- 考研数学笔记26~30
- 第6章 优先队列(堆)
- Html5-快捷键总览(window)
- 网络编程之新闻案例
- 类加载器