Я пытаюсь отобразить данные в текстовых изображениях, которые выведены из массива json.android json object string display in textview
я получить правильный ответ сервера и первый тост отображается правильно де JSON массив { "андроида": { "всего": 4}}
страница РНР онлайн http://www.2w.cl/apps/db/cargar_resultados.php
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<String, String, JSONObject> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected JSONObject doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
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 < 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();
}
}
}
}
тост «test2» ничего не отображает.
Спасибо за помощь
post logcat (и прочитайте его, вы увидите, что он объясняет, что ваш ответ json не является массивом.) – njzk2