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();
I have this code and this returns the "temp" string. I wanted to parse this string to JSON object and I also added the json-simple 1.1.1.jar to my refferenced libraries. But the classnotfound error and classdeffound errors shows up in log cat. how to resolve this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…