做json的测试,但是发现报错,具体错误为

 

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap
at net.sf.json.JSONObject.<init>(JSONObject.java:1529)
at net.sf.json.util.CycleDetectionStrategy.<clinit>(CycleDetectionStrategy.java:37)
at net.sf.json.JsonConfig.<clinit>(JsonConfig.java:58)
at net.sf.json.JSONArray.fromObject(JSONArray.java:127)
at JsonTest.main(JsonTest.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.map.ListOrderedMap
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 5 more

 

 

后来查了一下发现是包有错,使用json常用到的包有以下六个。

commons-logging-1.0.4.jar
commons-lang-2.3.jar
commons-collections-3.2.jar
commons-beanutils-1.7.0.jar
json-lib-2.2.1-jdk15.jar
ezmorph-1.0.4.jar

另外如果commons-collections-3.2.jar没有或版本不对的话会出现

org/apache/commons/collections/map/ListOrderedMap这个异常。

 

作者:xwdreamer