//list 转 json 数据 // List<Object> list = new ArrayList<Object>(); // list.add("zhangsan"); // list.add(0.34f); // JSONArray jsonArray = JSONArray.fromObject(list); // System.out.println(jsonArray.toString()); //map 转 json 数据 Map<String,Object> map = new HashMap<String,Object>(); map.put("name", "张三"); map.put("sex", "男"); JSONArray jsonArray = JSONArray.fromObject(map); System.out.println(jsonArray.toString()); JSONObject jsonObject = JSONObject.fromObject(map); System.out.println(jsonObject.toString()); // JsonUnit bean = new JsonUnit("zzd","man",30); // JSONArray jsonArray = JSONArray.fromObject(bean); // System.out.println(jsonArray.toString()); // JSONObject jsonObject = JSONObject.fromObject(bean); // System.out.println(jsonObject.toString());
json-lib-2.2.3.jar
[{"sex":"男","name":"张三"}]
{"sex":"男","name":"张三"}