Gustavo Serna Gustavo Serna - 3 months ago 10x
SQL Question

Android json array: how do I get and specific string?

I have a Json script which get data from a mysql database and print it in different textViews. The thing I want to know is how can I take for example only the "idE" value and print it in the "textViewTitulo" textview

try {
String response = "[{"0":"1","id":"1","1":"f3n","idE":"f3n","2":"bar","tipo":"bar"},{"0":"1","id":"1","1":"f3n","idE":"f3n","2":"bar2","tipo":"bar2"}]"
JSONArray array;
array = new JSONArray(response);

StringBuilder sb = new StringBuilder();
for (i=0; i<array.length(); i++) {
// chain each string, separated with a new line
sb.append(array.getString(i) + "\n");
// display the content on textview

} catch (JSONException e) {
// TODO Auto-generated catch block

My code works fine, but is displays the whole string of values


You have 2 objects in your JSONArray, and 1 textview to show the data in, so I'm adding append " " to separate them.

 for (i=0; i<array.length(); i++) {
        sb.append(" ");
        //do whatever with it