json字符串转java对象 出错

JSONObject jsonobject = JSONObject.fromObject(str);
main a = null;
a = (main)JSONObject.toBean(jsonobject, main.class);

main是我的java类。
字符串我在java里写就能正常工作。但通过http请求进来的字符串就不行,输出后跟Java里写的相同却依旧报错,找不到原因. 错误:
Servlet.service() for servlet [example] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: net/sf/json/JSONObject] with root cause
java.lang.NoClassDefFoundError: net/sf/json/JSONObject

项目缺少jar包。

<dependency>
  <groupId>net.sf.json-lib</groupId>
  <artifactId>json-lib</artifactId>
  <version>2.4</version>
  <classifier>jdk15</classifier>
</dependency>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-06-27
jar包引用有问题,你确认下呢
相似回答