2013-12-11 54 views
0

在我的Android应用程序..我用json连接服务器显示值..数据保存在服务器内..我得到的结果时,值是一个整数像1,2 ,3 ..我也能得到结果......但是当我试图像A,B,C那样得到char的值时,我没有得到结果......我给出了代码..请检查,如果有任何错误,请帮助。Android Json解析出错

String pid,number, heartnumber,personalitynumber,men,mhdnumber,mpnumber,chnum,pinnum,costone,custone,fvowel,lieno,hrpeno,exheno,rthno,pyno,pmnno,pdyno,scno,blno;  
TextView txtName, txtName1, txtName2,txtName3,txtName4,txtName5,txtName6,txtName7,txtName8,txtName9,txtName10,txtName11,txtName12,txtName13,txtName14,txtName15,txtName16,txtName17,txtName18,txtName19,txtName20; 

// Progress Dialog 
private ProgressDialog pDialog; 

// JSON parser class 
JSONParser jsonParser = new JSONParser(); 
private static final String url_cup_stone= "http://iascpl.com/app/get_cup_stone.php"; 
private static final String url_first_vowel= "http://iascpl.com/app/get_first_vowel.php"; 

private static final String TAG_CORNERSTONE = "cornerstone"; 
private static final String TAG_CUPSTONE = "cupstone"; 
TextView txt27 = (TextView) findViewById (R.id.textView48); 
txt27.setText(getIntent().getStringExtra("aChar")); 
TextView txt28 = (TextView) findViewById (R.id.textView51); 
txt28.setText(getIntent().getStringExtra("aChar1")); 

costone = txt27.getText().toString(); 
custone = txt28.getText().toString(); 

new GetProductDetails().execute(); 

class GetProductDetails extends AsyncTask<String, String, String> { 

    /** 
    * Before starting background thread Show Progress Dialog 
    * */ 
    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     pDialog = new ProgressDialog(FullExplanation.this); 
     pDialog.setMessage("Loading the result... Please wait..."); 
     pDialog.setIndeterminate(false); 
     pDialog.setCancelable(true); 
     pDialog.show(); 
    } 

    /** 
    * Getting product details in background thread 
    * */ 
    protected String doInBackground(String... args)  
    { 

     TextView txt27 = (TextView) findViewById (R.id.textView48); 
     TextView txt28 = (TextView) findViewById (R.id.textView51); 

     costone = txt27.getText().toString(); 

     custone = txt28.getText().toString(); 

     params.add(new BasicNameValuePair("costone", costone)); 
     params.add(new BasicNameValuePair("custone", custone)); 

     JSONObject json9 = jsonParser.makeHttpRequest(url_corner_stone, "GET", params); 

     JSONObject json10 = jsonParser.makeHttpRequest(url_cup_stone, "GET", params); 

     Log.d("Single Product Details", json9.toString()); 
     Log.d("Single Product Details", json10.toString()); 

     int success9 = json9.getInt(TAG_SUCCESS); 
     int success10 = json10.getInt(TAG_SUCCESS); 
     if (success9 == 1) { 
      // successfully received product details 
      JSONArray productObj = json9 
        .getJSONArray(TAG_PRODUCT); // JSON Array 

      // get first product object from JSON Array 
      final JSONObject product = productObj.getJSONObject(0); 

      // product with this pid found 
      // Edit Text 

      txtName9 = (TextView) findViewById(R.id.textView49); 


      runOnUiThread(new Runnable() { 
       @Override 
       public void run() 
       { 
        // TODO Auto-generated method stub 
        try { 

         txtName9.setText(product.getString(TAG_CORNERSTONE)); 
        } catch (JSONException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
       } 
      }); 

     }else{ 
      // product with pid not found 

     } 


     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 


     /** 
     * After completing background task Dismiss the progress dialog 
     * **/ 
    protected void onPostExecute(String file_url) { 
     // dismiss the dialog once got all details 
     pDialog.dismiss(); 
    } 
} 
} 

logcat的

58:00.251: I/Choreographer(5133): Skipped 50 frames! The application may be doing too much work on its main thread. 
12-11 08:58:01.021: I/Choreographer(5133): Skipped 200 frames! The application may be doing too much work on its main thread. 
12-11 08:58:01.851: I/Choreographer(5133): Skipped 31 frames! The application may be doing too much work on its main thread. 
12-11 08:58:02.231: I/Choreographer(5133): Skipped 69 frames! The application may be doing too much work on its main thread. 
12-11 08:58:03.751: I/Choreographer(5133): Skipped 52 frames! The application may be doing too much work on its main thread. 
12-11 08:58:03.971: I/Choreographer(5133): Skipped 55 frames! The application may be doing too much work on its main thread. 
12-11 08:58:04.331: I/Choreographer(5133): Skipped 48 frames! The application may be doing too much work on its main thread. 
12-11 08:58:04.491: I/Choreographer(5133): Skipped 34 frames! The application may be doing too much work on its main thread. 
12-11 08:58:04.641: I/Choreographer(5133): Skipped 37 frames! The application may be doing too much work on its main thread. 
12-11 08:58:04.851: I/Choreographer(5133): Skipped 54 frames! The application may be doing too much work on its main thread. 
12-11 08:58:05.141: I/Choreographer(5133): Skipped 63 frames! The application may be doing too much work on its main thread. 
12-11 08:58:05.391: I/Choreographer(5133): Skipped 37 frames! The application may be doing too much work on its main thread. 
12-11 08:58:05.791: I/Choreographer(5133): Skipped 42 frames! The application may be doing too much work on its main thread. 
12-11 08:58:05.931: I/Choreographer(5133): Skipped 35 frames! The application may be doing too much work on its main thread. 
12-11 08:58:06.341: I/Choreographer(5133): Skipped 105 frames! The application may be doing too much work on its main thread. 
12-11 08:58:06.531: I/Choreographer(5133): Skipped 49 frames! The application may be doing too much work on its main thread. 
12-11 08:58:06.791: I/Choreographer(5133): Skipped 68 frames! The application may be doing too much work on its main thread. 
12-11 08:58:07.051: I/Choreographer(5133): Skipped 58 frames! The application may be doing too much work on its main thread. 
12-11 08:58:07.301: I/Choreographer(5133): Skipped 34 frames! The application may be doing too much work on its main thread. 
12-11 08:58:07.521: I/Choreographer(5133): Skipped 43 frames! The application may be doing too much work on its main thread. 
12-11 08:58:07.651: I/Choreographer(5133): Skipped 32 frames! The application may be doing too much work on its main thread. 
12-11 08:58:08.721: D/dalvikvm(5133): GC_CONCURRENT freed 251K, 9% free 4257K/4632K, paused 77ms+14ms, total 199ms 
12-11 08:58:12.631: D/dalvikvm(5133): GC_CONCURRENT freed 405K, 11% free 4374K/4900K, paused 76ms+89ms, total 280ms 
12-11 08:58:16.161: D/dalvikvm(5133): GC_CONCURRENT freed 545K, 14% free 4373K/5040K, paused 77ms+89ms, total 326ms 
12-11 08:58:16.772: D/Single Product Details(5133): {"product":[{"created_at":"2013-11-04 02:43:45","number":null,"pid":"1","updated_at":"0000-00-00 00:00:00","description":"This is the prediction for destiny number 1."}],"success":1} 
12-11 08:58:16.772: D/Single Product Details(5133): {"product":[{"created_at":"2013-11-04 02:45:57","talent":"This is the prediction for talent number 8.","number":"8","pid":"8","updated_at":"0000-00-00 00:00:00","description":"This is the prediction for destiny number 8."}],"success":1} 
12-11 08:58:16.811: D/Single Product Details(5133): {"product":[{"heartnumber":"5","updated_at":"0000-00-00 00:00:00","heart":"This is the prediction for heart number 5.","description":"This is the prediction for destiny number 5.","created_at":"2013-11-04 02:45:22","talent":"This is the prediction for talent number 5.","number":"5","pid":"5"}],"success":1} 
12-11 08:58:16.841: D/Single Product Details(5133): {"product":[{"created_at":"2013-11-11 22:24:52","pid":"5","updated_at":"0000-00-00 00:00:00","personality":"This is the prediction for Personality Number 5.","personalitynumber":"5"}],"success":1} 
12-11 08:58:16.871: D/Single Product Details(5133): {"product":[{"created_at":"2013-11-11 22:28:18","menp":"This is the prediction for Minor Expression Number 11.","pid":"11","updated_at":"0000-00-00 00:00:00","men":"11","personality":"This is the prediction for Personality Number 11.","personalitynumber":"11"}],"success":1} 
12-11 08:58:16.911: D/Single Product Details(5133): {"product":[{"menp":"This is the prediction for Minor Expression Number 1.","updated_at":"0000-00-00 00:00:00","created_at":"2013-11-11 22:19:51","pid":"1","men":"1","mhd":"This is the prediction for Minor Heart Desire Number 1.","personality":"This is the prediction for Personality Number 1.","mhdnumber":"1","personalitynumber":"1"}],"success":1} 
12-11 08:58:16.941: D/Single Product Details(5133): {"product":[{"menp":"This is the prediction for Minor Expression Number 1.","updated_at":"0000-00-00 00:00:00","created_at":"2013-11-11 22:19:51","pid":"1","mpnumber":"1","men":"1","mpn":"This is the prediction for Minor Personality Number 1.","mhd":"This is the prediction for Minor Heart Desire Number 1.","personality":"This is the prediction for Personality Number 1.","mhdnumber":"1","personalitynumber":"1"}],"success":1} 
12-11 08:58:16.981: D/Single Product Details(5133): {"product":[{"pinnacle":"This is the prediction for the Pinnacle Number 1","created_at":"2013-11-23 03:05:21","pid":"1","updated_at":"0000-00-00 00:00:00","challenge":"This is the prediction for Challenge number 1.","pinnum":"1","chnum":"1"}],"success":1} 
12-11 08:58:17.003: D/Single Product Details(5133): {"product":[{"pinnacle":"This is the prediction for Pinnacle Number 5.","created_at":"2013-11-23 03:08:57","pid":"5","updated_at":"0000-00-00 00:00:00","challenge":"This is the prediction for Challenge Number 5.","pinnum":"5","chnum":"5"}],"success":1} 
12-11 08:58:17.012: D/Single Product Details(5133): {"message":"No product found","success":0} 
12-11 08:58:17.025: D/Single Product Details(5133): {"message":"No product found","success":0} 
12-11 08:58:17.061: D/Single Product Details(5133): {"message":"No product found","success":0} 
12-11 08:58:17.091: D/Single Product Details(5133): {"product":[{"lieno":"7","hrpeno":"7","heartpersonality":"This is the prediction for Heart Desire\/Expression Bridge number 7.","lifepathexpression":"This is the prediction for LifePath\/Expression Bridge number 7.","updated_at":"0000-00-00 00:00:00","expressionheart":"This is the prediction for Heart Desire\/Expression Bridge number 7.","created_at":"2013-11-27 01:07:06","pid":"8","exheno":"7"}],"success":1} 
12-11 08:58:17.121: D/Single Product Details(5133): {"product":[{"lieno":"0","hrpeno":"0","heartpersonality":"This is the prediction for Heart Desire\/Personality Bridge number 0.","lifepathexpression":"This is the prediction for Life Path\/Expression Bridge number 0.","updated_at":"0000-00-00 00:00:00","expressionheart":"This is the prediction for Heart Desire\/Expression Bridge number 0.","created_at":"2013-11-27 01:01:20","pid":"1","exheno":"0"}],"success":1} 
12-11 08:58:17.161: D/Single Product Details(5133): {"product":[{"lieno":"4","hrpeno":"4","heartpersonality":"This is the prediction for Heart Desire\/Personality Bridge number 4.","lifepathexpression":"This is the prediction for LifePath\/Expression Bridge number 4.","updated_at":"0000-00-00 00:00:00","expressionheart":"This is the prediction for Heart Desire\/Expression Bridge number 4.","created_at":"2013-11-27 01:05:27","pid":"5","exheno":"4"}],"success":1} 
12-11 08:58:17.201: D/Single Product Details(5133): {"product":[{"updated_at":"0000-00-00 00:00:00","pyno":"5","pdyno":"5","pmnno":"5","pdaynumber":"This is the prediction for Personal Day Number 5.","pmonthnumber":"This is the prediction for Personal Month Number 5.","pyearnumber":"This is the prediction for Personal Year Number 5.","created_at":"2013-11-28 01:16:49","rthoughtnumber":"This is the prediction for Relational Thought Number 5.","pid":"5","rthno":"5"}],"success":1} 
12-11 08:58:17.231: D/Single Product Details(5133): {"product":[{"updated_at":"0000-00-00 00:00:00","pyno":"11","pdyno":"11","pmnno":"11","pdaynumber":"This is the prediction for Personal Day Number 11.","pmonthnumber":"This is the prediction for Personal Month Number 11.","pyearnumber":"This is the prediction for Personal Year Number 11.","created_at":"2013-11-28 01:23:11","rthoughtnumber":"This is the prediction for Relational Thought Number 11.","pid":"10","rthno":"11"}],"success":1} 
12-11 08:58:17.262: D/Single Product Details(5133): {"product":[{"updated_at":"0000-00-00 00:00:00","pyno":"5","pdyno":"5","pmnno":"5","pdaynumber":"This is the prediction for Personal Day Number 5.","pmonthnumber":"This is the prediction for Personal Month Number 5.","pyearnumber":"This is the prediction for Personal Year Number 5.","created_at":"2013-11-28 01:16:49","rthoughtnumber":"This is the prediction for Relational Thought Number 5.","pid":"5","rthno":"5"}],"success":1} 
12-11 08:58:17.291: D/Single Product Details(5133): {"product":[{"updated_at":"0000-00-00 00:00:00","pyno":"7","pdyno":"7","pmnno":"7","pdaynumber":"This is the prediction for Personal Day Number 7.","pmonthnumber":"This is the prediction for Personal Month Number 7.","pyearnumber":"This is the prediction for Personal Year Number 7.","created_at":"2013-11-28 01:18:33","rthoughtnumber":"This is the prediction for Relational Thought Number 7.","pid":"7","rthno":"7"}],"success":1} 
12-11 08:58:17.301: D/Single Product Details(5133): {"product":[{"balance":"This is the prediction for the Balance Number 1.","karmic":"This is the prediction for the Karmic Lesson 1.","klno":"1","updated_at":"0000-00-00 00:00:00","blno":"1","created_at":"2013-11-29 04:17:10","pid":"1","scno":"1","subconcious":"This is the prediction for the Sub-Concious Self 1.","hiddenpassion":"This is the prediction for the Hidden Passion 1.","hpno":"1"}],"success":1} 
12-11 08:58:17.321: D/Single Product Details(5133): {"product":[{"balance":"This is the prediction for the Balance Number 3.","karmic":"This is the prediction for the Karmic Lesson 3.","klno":"3","updated_at":"0000-00-00 00:00:00","blno":"3","created_at":"2013-11-29 04:19:31","pid":"3","scno":"3","subconcious":"This is the prediction for the Sub-Concious Self 3.","hiddenpassion":"This is the prediction for the Hidden Passion Number 3.","hpno":"3"}],"success":1} 
12-11 08:58:18.811: I/Choreographer(5133): Skipped 183 frames! The application may be doing too much work on its main thread. 
12-11 08:58:18.981: I/Choreographer(5133): Skipped 31 frames! The application may be doing too much work on its main thread. 
12-11 08:58:20.911: I/Choreographer(5133): Skipped 38 frames! The application may be doing too much work on its main thread. 
12-11 08:58:21.071: I/Choreographer(5133): Skipped 30 frames! The application may be doing too much work on its main thread. 
12-11 08:58:22.151: I/Choreographer(5133): Skipped 103 frames! The application may be doing too much work on its main thread. 
12-11 08:58:22.301: I/Choreographer(5133): Skipped 30 frames! The application may be doing too much work on its main thread. 
12-11 08:58:22.661: I/Choreographer(5133): Skipped 79 frames! The application may be doing too much work on its main thread. 
12-11 08:58:22.972: I/Choreographer(5133): Skipped 59 frames! The application may be doing too much work on its main thread. 
12-11 08:58:23.721: I/Choreographer(5133): Skipped 31 frames! The application may be doing too much work on its main thread. 
12-11 08:58:23.951: I/Choreographer(5133): Skipped 42 frames! The application may be doing too much work on its main thread. 
12-11 08:58:24.242: I/Choreographer(5133): Skipped 44 frames! The application may be doing too much work on its main thread. 
12-11 08:58:25.291: I/Choreographer(5133): Skipped 33 frames! The application may be doing too much work on its main thread. 
12-11 08:58:25.601: I/Choreographer(5133): Skipped 33 frames! The application may be doing too much work on its main thread. 
12-11 08:58:25.761: I/Choreographer(5133): Skipped 42 frames! The application may be doing too much work on its main thread. 
12-11 08:58:25.912: I/Choreographer(5133): Skipped 38 frames! The application may be doing too much work on its main thread. 
12-11 08:58:26.881: I/Choreographer(5133): Skipped 42 frames! The application may be doing too much work on its main thread. 
12-11 08:58:27.163: I/Choreographer(5133): Skipped 39 frames! The application may be doing too much work on its main thread. 
12-11 08:58:27.451: I/Choreographer(5133): Skipped 39 frames! The application may be doing too much work on its main thread. 
12-11 08:58:28.322: I/Choreographer(5133): Skipped 62 frames! The application may be doing too much work on its main thread. 
12-11 08:58:28.551: I/Choreographer(5133): Skipped 34 frames! The application may be doing too much work on its main thread. 
12-11 08:58:28.711: I/Choreographer(5133): Skipped 42 frames! The application may be doing too much work on its main thread. 
12-11 08:58:28.872: I/Choreographer(5133): Skipped 31 frames! The application may be doing too much work on its main thread. 
12-11 08:58:31.291: I/Choreographer(5133): Skipped 36 frames! The application may be doing too much work on its main thread. 
12-11 08:58:31.591: I/Choreographer(5133): Skipped 44 frames! The application may be doing too much work on its main thread. 
12-11 08:58:31.813: I/Choreographer(5133): Skipped 38 frames! The application may be doing too much work on its main thread. 
12-11 08:58:31.971: I/Choreographer(5133): Skipped 40 frames! The application may be doing too much work on its main thread. 
12-11 08:58:32.131: I/Choreographer(5133): Skipped 31 frames! The application may be doing too much work on its main thread. 
12-11 08:58:32.761: I/Choreographer(5133): Skipped 58 frames! The application may be doing too much work on its main thread. 
12-11 08:58:32.981: I/Choreographer(5133): Skipped 31 frames! The application may be doing too much work on its main thread. 
12-11 08:58:33.251: I/Choreographer(5133): Skipped 31 frames! The application may be doing too much work on its main thread. 
12-11 08:58:34.721: I/Choreographer(5133): Skipped 43 frames! The application may be doing too much work on its main thread. 
12-11 08:58:34.881: I/Choreographer(5133): Skipped 40 frames! The application may be doing too much work on its main thread. 
12-11 08:58:35.041: I/Choreographer(5133): Skipped 30 frames! The application may be doing too much work on its main thread. 
12-11 08:58:35.212: I/Choreographer(5133): Skipped 44 frames! The application may be doing too much work on its main thread. 
12-11 08:58:35.351: I/Choreographer(5133): Skipped 35 frames! The application may be doing too much work on its main thread. 
12-11 08:58:35.482: I/Choreographer(5133): Skipped 33 frames! The application may be doing too much work on its main thread. 
12-11 08:58:36.492: I/Choreographer(5133): Skipped 30 frames! The application may be doing too much work on its main thread. 
12-11 08:58:39.071: I/Choreographer(5133): Skipped 71 frames! The application may be doing too much work on its main thread. 
12-11 08:58:39.321: I/Choreographer(5133): Skipped 43 frames! The application may be doing too much work on its main thread. 
12-11 08:58:39.611: I/Choreographer(5133): Skipped 63 frames! The application may be doing too much work on its main thread. 
12-11 08:58:39.981: I/Choreographer(5133): Skipped 45 frames! The application may be doing too much work on its main thread. 
12-11 08:58:40.271: I/Choreographer(5133): Skipped 36 frames! The application may be doing too much work on its main thread. 
12-11 08:58:40.572: I/Choreographer(5133): Skipped 61 frames! The application may be doing too much work on its main thread. 
12-11 08:58:40.801: I/Choreographer(5133): Skipped 35 frames! The application may be doing too much work on its main thread. 
12-11 08:58:40.971: I/Choreographer(5133): Skipped 34 frames! The application may be doing too much work on its main thread. 
12-11 08:58:41.151: I/Choreographer(5133): Skipped 36 frames! The application may be doing too much work on its main thread. 
12-11 08:58:41.481: I/Choreographer(5133): Skipped 44 frames! The application may be doing too much work on its main thread. 
12-11 08:58:42.571: I/Choreographer(5133): Skipped 33 frames! The application may be doing too much work on its main thread. 
12-11 08:58:42.861: I/Choreographer(5133): Skipped 35 frames! The application may be doing too much work on its main thread. 
12-11 08:58:44.141: I/Choreographer(5133): Skipped 43 frames! The application may be doing too much work on its main thread. 
12-11 08:58:44.291: I/Choreographer(5133): Skipped 30 frames! The application may be doing too much work on its main thread. 
12-11 08:58:44.831: I/Choreographer(5133): Skipped 30 frames! The application may be doing too much work on its main thread. 
12-11 08:58:45.021: I/Choreographer(5133): Skipped 46 frames! The application may be doing too much work on its main thread. 
12-11 08:58:45.201: I/Choreographer(5133): Skipped 34 frames! The application may be doing too much work on its main thread. 
12-11 08:58:45.371: I/Choreographer(5133): Skipped 45 frames! The application may be doing too much work on its main 
+3

你能不能请你格式化你的代码,并在你编写这段代码的时候发布堆栈跟踪 – Raghunandan

+0

格式化,你可以看到很多错误。其中之一可能是doInBackground有两个catch块,但最后一个是错误的。 –

+0

但它是显示正确的值时,整数解析......但只有它的char不起作用 – roshanpeter

回答

3

CustomHttpClient.java

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.net.URI; 
import java.util.ArrayList; 

import org.apache.http.HttpResponse; 
import org.apache.http.NameValuePair; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.entity.UrlEncodedFormEntity; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.conn.params.ConnManagerParams; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.params.HttpConnectionParams; 
import org.apache.http.params.HttpParams; 

public class CustomHttpClient { 
/** The time it takes for our client to timeout */ 
public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds 

/** Single instance of our HttpClient */ 
private static HttpClient mHttpClient; 

/** 
* Get our single instance of our HttpClient object. 
* 
* @return an HttpClient object with connection parameters set 
*/ 
private static HttpClient getHttpClient() { 
    if (mHttpClient == null) { 
     mHttpClient = new DefaultHttpClient(); 
     final HttpParams params = mHttpClient.getParams(); 
     HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT); 
     HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT); 
     ConnManagerParams.setTimeout(params, HTTP_TIMEOUT); 
    } 
    return mHttpClient; 
} 

/** 
* Performs an HTTP Post request to the specified url with the 
* specified parameters. 
* 
* @param url The web address to post the request to 
* @param postParameters The parameters to send via the request 
* @return The result of the request 
* @throws Exception 
*/ 
public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception { 
    BufferedReader in = null; 
    try { 
     HttpClient client = getHttpClient(); 
     HttpPost request = new HttpPost(url); 
     UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters); 
     request.setEntity(formEntity); 
     HttpResponse response = client.execute(request); 
     in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 

     StringBuffer sb = new StringBuffer(""); 
     String line = ""; 
     String NL = System.getProperty("line.separator"); 
     while ((line = in.readLine()) != null) { 
      sb.append(line + NL); 
     } 
     in.close(); 

     String result = sb.toString(); 
     return result; 
    } finally { 
     if (in != null) { 
      try { 
       in.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 

/** 
* Performs an HTTP GET request to the specified url. 
* 
* @param url The web address to post the request to 
* @return The result of the request 
* @throws Exception 
*/ 
public static String executeHttpGet(String url) throws Exception { 
    BufferedReader in = null; 
    try { 
     HttpClient client = getHttpClient(); 
     HttpGet request = new HttpGet(); 
     request.setURI(new URI(url)); 
     HttpResponse response = client.execute(request); 
     in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 

     StringBuffer sb = new StringBuffer(""); 
     String line = ""; 
     String NL = System.getProperty("line.separator"); 
     while ((line = in.readLine()) != null) { 
      sb.append(line + NL); 
     } 
     in.close(); 

     String result = sb.toString(); 
     return result; 
    } finally { 
     if (in != null) { 
      try { 
       in.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 

}

 String url=("http://www.avayainfoways.com/hetal/android/index.php?test=" + LeaderBoard.this.test + "&testnm=" + LeaderBoard.this.testFile); 
      //String url=("http://www.avayainfoways.com/hetal/android/index.php?test=MATHS&testnm=Maths_1"); 
      //response=myuri.toString().trim(); 
      Log.d("URL",url); 
     // Making a request to url and getting response 
     //String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET); 
     String jsons = CustomHttpClient.executeHttpGet(url); 

     Log.d("Response: ", "> " + jsons); 

     if (jsons != null) 
     { 
      try { 
       JSONObject jsonObj = new JSONObject(jsons); 

       // Getting JSON Array node 
       contacts = jsonObj.getJSONArray(TAG_CONTACTS); 

       // looping through All Contacts 
       for (int i = 0; i < contacts.length(); i++) { 
        JSONObject c = contacts.getJSONObject(i); 

        String email = c.getString(TAG_EMAIL); 
        String test = c.getString(TAG_TEST); 
        String testnm = testname; 
        String score = c.getString(TAG_SCORE); 



        // tmp hashmap for single contact 
        HashMap<String, String> contact = new HashMap<String, String>(); 

        // adding each child node to HashMap key => value 
        contact.put(TAG_EMAIL, email); 
        contact.put(TAG_TEST, test); 
        contact.put(TAG_TESTNM, testnm); 
        contact.put(TAG_SCORE, score+" Marks"); 

        // adding contact to contact list 
        contactList.add(contact); 
       } 
      } 
      catch (JSONException e) 
      { 
       e.printStackTrace(); 
      } 
     } 
     else 
     { 
      Log.e("ServiceHandler", "Couldn't get any data from the url"); 
     } 
    } catch (Exception e) 
    { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
    } 
    finally 
    { 

    } 
     return null; 
}