用谷歌自带的Json类解析时遇到的java.lang.NoClassDefFoundError: org/json/JSONException问题

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)

... 6 more

问题是上面这样的,自己捣鼓了半天,看问题代码应该是缺少org.json.JSONException这个类,说这个类没有找到。

网上找了半天还是没有找到解决办法,突然想到导入一个json的包看是否可行。

我倒了一个org.json.jar到项目的lib目录下,再一编译就可以了。

下面是json.org下载的路径:

http://download.csdn.net/detail/u013476751/8173517

本来开始用的Java的那套解析Json,但是也是编译不过,捣鼓了半天还是用谷歌的Json解析类来解析Json。

哎,真麻烦。

下面是一个用谷歌自带类解析单个Json的例子,其他解析Json的方法也大同小异,自己可以百度查找一下其他方法。

public static JSONArray getQuestionJson(String jsonStr) {
	JSONArray jsonArray = new JSONArray();
	JSONTokener tokener = new JSONTokener(jsonStr);
	try {
		JSONObject question = (JSONObject) tokener.nextValue();
		jsonArray.put(0, question.get("id"));
		jsonArray.put(1, question.get("fid"));
		jsonArray.put(2, question.get("type"));
		jsonArray.put(3, question.get("question"));
		jsonArray.put(4, question.get("config"));
		jsonArray.put(5, question.get("answer"));
		jsonArray.put(6, question.get("jiexi"));
		jsonArray.put(7, question.get("ceshi"));
		jsonArray.put(8, question.get("uid"));
		jsonArray.put(9, question.get("username"));
		jsonArray.put(10, question.get("ifshare"));
		jsonArray.put(11, question.get("yz"));
		jsonArray.put(12, question.get("difficult"));
		jsonArray.put(13, question.get("yema"));
		jsonArray.put(14, question.get("answer"));
		jsonArray.put(15, question.get("star"));
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return jsonArray;
}
好了,这个问题就扯到这了,真他娘麻烦。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值