需要包:
commons-collections-3.2.jar
ezmorph-1.0.6.jar
json-lib-2.3-jdk15.jar
commons-logging-1.0.4.jar
commons-logging-1.0.4.jar
测试代码
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap map = new HashMap();
map.put("1", "1");
map.put("2", "2");
map.put("3", "3");
map.put("4", "4");
JSONArray jsonArray = JSONArray.fromObject(map);
System.out.println(jsonArray);
}
输出结果
[{"3":"3","2":"2","4":"4","1":"1"}]