title: android json object string display in textview
body: <p>I am trying to display data in textviews that are exracted from a json array.</p>
  
  <p>i get a correct server answer and the first toast displays correctly de json array {"android":{"total":4}}</p>
  
  <p>The php page is online <a href="http://www.2w.cl/apps/db/cargar_resultados.php" rel="nofollow">http://www.2w.cl/apps/db/cargar_resultados.php</a></p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.http.NameValuePair;
  import org.apache.http.message.BasicNameValuePair;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.app.Activity;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class SeeResults extends Activity{
  
      TextView texto;
  
      JSONArray android = null;
      JSONParser jsonParser = new JSONParser();
      private static String url = "http://www.2w.cl/apps/db/cargar_resultados.php/";
      private static final String TAG_OS = "android";
      private static final String TAG_CONSULTA = "total";
  
      public String idconsulta;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.see_results);
          idconsulta = getIntent().getStringExtra("test");
  
          TextView tv = null;
          tv = (TextView)findViewById(R.id.textView1);
          tv.setText(idconsulta);
  
          Toast.makeText(this, "On Create Called" + idconsulta, Toast.LENGTH_LONG).show();
      }
  
      @Override
      protected void onStart() {
          // TODO Auto-generated method stub
          super.onStart();
          new JSONParse().execute();
          Toast.makeText(this, "On Start Called", Toast.LENGTH_LONG).show();
      }
  
  
      private class JSONParse extends AsyncTask&lt;String, String, JSONObject&gt; {
  
         @Override
           protected void onPreExecute() {
               super.onPreExecute();
  
         }
         @Override
          protected JSONObject doInBackground(String... args) {
  
              // Building Parameters
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("idconsultas", idconsulta));
              JSONObject json = jsonParser.makeHttpRequest(url, "POST", params);
  
              return json;
          }
  
          @Override
            protected void onPostExecute(JSONObject json) {
  
              Toast.makeText(getBaseContext(), "test" + json, Toast.LENGTH_LONG).show();
  
            try {
               android = json.getJSONArray(TAG_OS);
               for(int i = 0; i &lt; android.length(); i++){  
               JSONObject c = android.getJSONObject(i);
  
               String total = c.getString(TAG_CONSULTA);
               Toast.makeText(getBaseContext(), "test2" + total, Toast.LENGTH_LONG).show();
               TextView tv = null;
               tv = (TextView)findViewById(R.id.textView1);
               tv.setText(total);
               }
           } catch (JSONException e) {
             e.printStackTrace();
           }
  
          }
       }
  
  
  }
  </code></pre>
  
  <p>the toast "test2" does not display anything.</p>
  
  <p>Thanks for helping</p>