日期:2014-05-16  浏览次数:20412 次

json-lib小东西记录
Json-lib還需要以下 Library:
json-lib-2.1.jar
commons-lang 2.4
commons-beanutils 1.7.0
commons-collections 3.2
commons-logging 1.1.1
ezmorph 1.0.6


commons-beanutils.jar不加这个包
java.lang.NoClassDefFoundError: org/apache/commons/beanutils/DynaBean
commons-collections.jar 不加这个包
java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap
commons-lang.jar不加这个包
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
commons-logging.jar不加这个包
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
ezmorph.jar不加这个包
java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
json-lib.jar不加这个包
java.lang.NoClassDefFoundError: net/sf/json/JSONObject

配置去除掉哪些字段
JsonConfig config=new JsonConfig();
config.setExcludes(new String[]{"creationDate","baseClasses","baseOfficialStudents"});

list转换
JSONArray jsonList=JSONArray.fromObject(List,config);
对象转换
JSONObject json=JSONObject.fromObject(Object);

设置输出编码解决中文乱码
getResponse().setContentType("text/html;charset=utf-8");
getResponse().setHeader("Cache-Control", "no-cache");