日期:2014-05-18  浏览次数:20772 次

json问题。
我的jdk版本是1.4.2
别人给了我个json-lib-2.2.1-jdk15.jar。
Java code

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;




public class JsonDemo {

    public JsonDemo(){}

    public static String formToJson(Object o){
        JSONObject jo=JSONObject.fromObject(o);
        return jo.toString();
    }
    public static String listToJson(List l){
        JSONArray jo=JSONArray.fromObject(l);
        return jo.toString();
    }
    
    public static void main(String[] args){
        
        String str[]={"aaa","bbb","ccc"};
        System.out.println("formToJson="+formToJson(str));
    }
}


我运行个程序出现下面异常

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at JsonDemo.formToJson(JsonDemo.java:14)
at JsonDemo.main(JsonDemo.java:25)




------解决方案--------------------
引用楼主 xuantian868 的帖子:
codeimportjava.util.List;importnet.sf.json.JSONArray;importnet.sf.json.JSONObject;publicclassJsonDemo