JSON学习(三):Json与常见的类型之间的转换
2017-04-10 15:04
441 查看
list转json
List list=new ArrayList(); list.add("1"); list.add("2"); JsonArray json=JsonArray.fromObject(list);map转json
Map map = new HashMap(); map.put("欧尼", "json"); map.put("听我", Boolean.TRUE); map.put("three", new Integer(1)); JSONObject json = JSONObject.fromObject(map);Bean转换成json代码
JsonBean jb=new JsonBean() JSONObject jsonObject = JSONObject.fromObject(jb);数组转换成json代码
int [] arr = new int[] { 1,2,3}; JSONArray jsonarray = JSONArray.fromObject(arr);转换成json代码
JSONArray jsonarr = JSONArray.fromObject("['json','is','easy']" );
String jsonStr = "{\"id\": 2," + " \"title\": \"json title\", " + "\"config\": {" + "\"name\": 34," + "\"type\": 35," + "}, \"class\": [" + "\"one\", \"two\", \"three\"" + "]}"; //转换成为JSONObject对象 JSONObject jsonObj = new JSONObject(jsonStr);
相关文章推荐
- fastjson - 之常见的数据类型与json的相互转换
- php学习之数据类型之间的转换介绍
- xstream学习,对象和xml之间转换,对象和json之间转换
- Java开发学习--Java 中基本类型和包装类之间的转换
- C#学习笔记1-类型之间的转换 分享修改删除
- fastjson 之常见的数据类型与json的相互转换
- PHP学习(四)--数据类型之间相互转换
- Python学习(三)---常见类型转换、数值操作、序列操作
- JSON: Python Objects与String之间转换【json.dumps把python任意数据类型转换成字符串,json.loads把字符串转换为unicode编码】
- php学习之数据类型之间的转换代码
- fastjson 之常见的数据类型与json的相互转换
- java常见数据类型之间的转换
- Java基础学习19(String类型对象在内存中的分布以及与包装类之间的转换)
- 常见Java 中数据类型之间的转换的方法!
- php学习之------[数据类型之间的转换]
- 常见Java 中数据类型之间的转换的方法!
- 【JAVA学习】java基本数据类型与字符串之间的转换(基本数据类型、对象封装类、自动装箱、自动拆箱)
- Java学习之基本类型与字符串之间的转换
- Java中常见基本类型之间的转换
- 不同数据类型与Json之间的转换