SONObject jsonObject=JSONObject.fromObject(map) 执行到这的时候没有任何反应,并且不报错

来源:互联网 发布:斗鱼王师傅c语言视频 编辑:程序博客网 时间:2024/06/05 21:04

今天利用struts2解析json数据时,

JSONObject jsonObject=JSONObject.fromObject(map) 执行到这的时候没有任何反应,并且不报错 ,后面找各种资料,都是说缺包引起的,但我的包都加了,只会多不会少的,后面用断点调试,发现了一个异常

java.lang.NoClassDefFoundError:org/apache/commons/lang/exception/NestableRuntimeException 
百度后发现,是因为.commons-lang3-3.1.jar包中没有这个类引起的,新版本的包中没有这个类,没办法,只有引入老版本的包了,就是下面的commons-lang-2.3.jar或者2.4,2.5都可以
确实,后面我打开两个这两个jar文件,对比,新版本的包中没有NestableRuntimeException.class
而老版本的却有,截图如下

请认真对比....

下面是解析json需要的包

导入解析json数据需要的包

1.commons-beanutils-1.7.0.jar

2.commons-collections-3.2.1.jar

3.commons-lang-2.3.jar    (这里要用老版本的,可以打开看一下,里面目录exception下是否有NestableRuntimeException.class

4.commons-logging-1.0.4.jar

5.ezmorph-1.0.3.jar   

6.json-lib-2.1.jar

action中的代码   

      Map<String,Object> map = new HashMap<String,Object>();      System.out.println("here1.5");      map.put("MYname", "jiajia");      System.out.println("here1.6");      map.put("age","22");      System.out.println("here1.7");         map.put("position","3");      System.out.println("here1.8");      System.out.println(""+map.get("age"));      JSONObject json = JSONObject.fromObject(map);//将map对象转换成json类型数据      System.out.println("here1.9");      this.name = json.toString();//给result赋值,传递给页面      System.out.println("here2");


0 0
原创粉丝点击