定义对象、定义映射,使用json库转换 Gson gson = new GsonBuilder().create(); Type type = new TypeToken() {}.getType(); HashMap map = (HashMap)gson.fromJson(json, type);
我的理解是json格式有对象或数值的形式.jsonObject是对单个对象的,jsonArray是对数组(集合)的.map是一个对象用的是jsonObject,而list集合就要用jsonArray.--没测试过,有错误麻烦指正.
定义对象、定义映射,使用json库转换 gson gson = new gsonbuilder().create(); type type = new typetoken() {}.gettype(); hashmap map = (hashmap)gson.fromjson(json, type);
自己循环遍历,构造就好了.json和map都是key-value的格式.
三、json-lib的JSONArray和List的相互转换.1.List转JSONArray./*** JSON-Lib List转JSONArray*/@Testpublic void list2JSONArray() { //创建一个List List list = new ArrayList(); JSONModel model = new JSONModel(); model.setAge(10); model.
有专门的 转json 工具 会自动把 hibernate中关联的对象一块转成json如果需要加入 json-lib.jar包 这个包 有list 转json map 转json 等
List> list=new ArrayList(); Map m1=new HashMap(); m1.put(“xx”, “yyyy-mm-dd”); m1.put(“xxx.”, "yyyy-mm-dd"); list.add(m1); Map m2=list.get(0); Set s=m2.entrySet(); Iterator it=s.iterator(); while(it.hasNext()){ Map.Entry e=(Map.Entry)it.
替换一下=替换成:手工和变成都可以呀!
把map转成json的步骤:1、需要一些jar包:json-lib-2.4-jdk15.jar、ezmorph-1.0.6.jar、commons-logging.jar、commons-lang.jar、commons-collections.jar、commons-beanutils.jar.2、把Map转换成json, 要使用jsonObject对象:Map<String,
{"iBusinessID":"1","iAddressID":"1","iManagerID":"","iMemberID":"","iMemberOrgID":"","iAssessor":"0","iMaker":"{$loginUserID}","iPayee":"{$loginUserID}","iTransactor":"0","iWicketID":"{$