Android Gson中的Map与JSON相互切换
来源:互联网 发布:数控车床初级编程视频 编辑:程序博客网 时间:2024/06/01 09:41
源:
{ "mapBean": { "mapBean-key1": { "id": "1", "name": "cyy1" }, "mapBean-key2": { "id": "2", "name": "cyy2" } }, "mapString": { "mapString-key1": "values1", "mapString-key2": "values2" }}
解析Bean:
public static class Bean{ private String id; private String name; public Bean(){ } public Bean(String id, String name){ this.id = id; this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; }}public static class BeanMap{ private Map<String, String> mapString; private Map<String, Bean> mapBean; public Map<String, String> getMapString() { return mapString; } public void setMapString(Map<String, String> mapString) { this.mapString = mapString; } public Map<String, Bean> getMapBean() { return mapBean; } public void setMapBean(Map<String, Bean> mapBean) { this.mapBean = mapBean; }}生成:
Map<String, String> mapString = new HashMap<>();Map<String, Bean> mapBean = new HashMap<>();mapString.put("mapString-key1", "values1");mapString.put("mapString-key2", "values2");mapBean.put("mapBean-key1", new Bean("1", "cyy1"));mapBean.put("mapBean-key2", new Bean("2", "cyy2"));BeanMap beanMap = new BeanMap();beanMap.setMapBean(mapBean);beanMap.setMapString(mapString);LogUtil.i("test-map", JsonUtil.toJson(beanMap));
阅读全文
0 0
- Android Gson中的Map与JSON相互切换
- Gson与Json相互转化
- 利用Gson使json字符串与java bean/list/map之间的相互转换
- Android JSON数据与实体类之间的相互转化-------GSON的用法
- Android JSON数据与实体类之间的相互转化-------GSON实现
- Java_jackson_bean/map/list与json相互转换
- Java:JSON与Map相互转换
- Json 与 Object 相互转换的 gson-1.4.jar
- android JSON解析之JSONObject与GSON
- android JSON解析之JSONObject与GSON
- Android中的JSON解析方式:json; Gson ; Fastjson
- Android中的JSON解析方式:json; Gson ; Fastjson
- Android中的JSON解析方式:json; Gson ; Fastjson
- Android JSON数据格式的解析,与简单对象、带泛型的List和Map的转换,以及GSON的使用
- Java中Bean与Map/Json/DBObject的相互转换
- Json与Gson
- GSON与Json 解析
- json与gson互转
- c++中的Raw String的Macro用法
- 搭建网站
- JsonObject生成Json字符串有转意字符
- 自己同学遇到的问题
- UVA11475
- Android Gson中的Map与JSON相互切换
- linux exec更新svn
- 通过 javascript 获取当前url地址相关信息
- verify 验证码生成控件
- 回顾Java基础知识——(1)
- selenium之 文件上传所有方法整理总结
- log4j:WARN No appenders could be found for logger
- 简单解决lnmp环境下不支持thinkphp路由(pathinfo模式)
- Angularjs学习笔记之一