1、错误描述
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/beanutils/DynaBean at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:230) at net.sf.json.JSONArray._processValue(JSONArray.java:2513) at net.sf.json.JSONArray.processValue(JSONArray.java:2538) at net.sf.json.JSONArray.addValue(JSONArray.java:2525) at net.sf.json.JSONArray._fromCollection(JSONArray.java:1056) at net.sf.json.JSONArray.fromObject(JSONArray.java:123) at net.sf.json.JSONArray.fromObject(JSONArray.java:105) at com.you.model.ListToJSON.main(ListToJSON.java:29) Caused by: java.lang.ClassNotFoundException: org.apache.commons.beanutils.DynaBean at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 8 more
/** * 将List转换成JSON */ package com.you.model; import java.util.ArrayList; import java.util.List; import net.sf.json.JSONArray; /** * @author YouHaiDong * */ public class ListToJSON { /** * @param args */ public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("春天"); list.add("夏天"); list.add("秋天"); list.add("冬天"); JSONArray jsonArray = JSONArray.fromObject(list); System.out.println("List转换成JSON:" + jsonArray.toString()); } }
3、解决办法
将“commons-beanutils-1.8.0.jar”复制到lib目录下
原文地址:http://blog.csdn.net/you23hai45/article/details/39162309