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-simple 1.1.1.jar 添加到我的引用库中。但是 classnotfound 错误和 classdeffound 错误出现在 log cat 中。如何解决这个问题?