new Thread(new Runnable() { public void run() { HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit HttpResponse response; JSONObject json = new JSONObject(); try{ HttpPost post = new HttpPost(URL); post.setHeader("Content-type", "application/json"); json.put("username", userName); json.put("password", password); StringEntity se = new StringEntity( json.toString()); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(se); response = client.execute(post); /*Checking response */ if(response!=null){ String temp = EntityUtils.toString(response.getEntity()); //Get the data in the entity JSONObject json2 = (JSONObject)new JSONParser().parse(temp); //JsonObject o = new JsonParser().parse(temp).getAsJsonObject(); Log.v("response", json2.get("state").toString()); }} catch(Exception e){ e.printStackTrace(); //createDialog("Error", "Cannot Estabilish Connection"); } } }).start();
我有这段代码,它返回“ temp”字符串。我想将此字符串解析为JSON对象,并且还向我的引用库中添加了JSON简单的1.1.1.jar。但是classnotfound错误和classdeffound错误显示在日志目录中。如何解决呢?
不要像这样添加jar文件。按照这些步骤
您应该尝试这样:
Remove``JARJava中对项目中所有的引用project -> properties -> Java build path -> libraries
Remove``JAR
project -> properties -> Java build path -> libraries
libs如果项目的根目录不存在,则创建一个文件JAR夹。将文件夹复制到libs文件夹。
libs
JAR
如果仍然无法运行,请确定。右键单击您的项目> Android工具>修复项目属性
清理您的项目并运行。它会工作