java转换json需导入的jar包说明
commons-beanutils-1.8.0.jar不加这个包
java.lang.NoClassDefFoundError: org/apache/commons/beanutils/DynaBean
commons-collections.jar 不加这个包
java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap
commons-lang-2.4.jar不加这个包
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
commons-logging-1.1.1.jar不加这个包
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
ezmorph-1.0.4.jar不加这个包
java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
json-lib-2.3-jdk15.jar不加这个包
java.lang.NoClassDefFoundError: net/sf/json/JSONObject
相应jar包可到网上下载,也可以用下面提供的!
实例:
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONArray;
public class JsonTest {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
boolean[] boolArray = new boolean[]{true,false,true};
JSONArray jsonArray = JSONArray.fromObject( boolArray );
System.out.println( jsonArray );
List list = new ArrayList();
list.add( "first" );
list.add( "second" );
JSONArray jsonArray2 = JSONArray.fromObject( list );
System.out.println( jsonArray2 );
}
}
posted on 2016-05-29 13:58 nickTimer 阅读(1007) 评论(0) 编辑 收藏 举报