1 .需要库:
commons-beanutils-1.7.0.jar
commons-collections-3.1.jar
公共语言- 2.1.jar
公共登录-1.1.3. jar
ezmorph-1.0.2.jar
json-lib-2.4-jdk15.jar
2 .转换方法:
//对象为json sqlModel model=new sqlModel (; 模型. setage (18; 模型. setheight (188.0; model.setName ()聪明的彩虹); 字符串JSON str=null; try { jsonobjectjsonobject=JSON object.from object (模型; jsonStr=jsonObject.toString (; 系统. out.println (JSON str; }catch(exceptione ) { System.out.println ) (数组迁移到json失败)结果(age ) :18,(Height ) :188,(name )
//数组反转jsonString jsonStr=null; try { jsonarrayjsonobject=JSON array.from object (mynamelist ); jsonStr=jsonObject.toString (; 系统. out.println (JSON str; }catch(exceptione ) { System.out.println )“数组迁移到json失败”(结果) ['aaaa、(bbbb )、(cccc )、) zzl、()