Can someone help guide me on how to parse JSONArray’s into TextViews? So far, everytime I parse it, It only shows me the last results, instead of everything.
So far I have:
try {
standby_position = json.getString("standby_position");
zone_name = json.getString("zone_name");
zone_no = json.getString("zone_no");
status = json.getString("status");
JSONArray standby_list = json.getJSONArray("standby_list");
for (int i1 = 0; i1 < standby_list.length(); i1++) {
JSONObject c = standby_list.getJSONObject(i1);
DRIVER = c.getString(driver);
SINCE = c.getString(since);
WAITING = c.getString(waiting);
GPS_DATA = c.getString(gps_data);
}
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
I was trying to to do:
TextView information = (TextView) findViewById(R.id.information);
information.setText ( DRIVER + SINCE + WAITING );
Here is what I am trying to parse:
{
"driver": "819",
"gps_data": "1",
"last_geocode": "",
"lastLatitudeUpdate": "12/31/1969 5:00:00 PM",
"standby_position": "1",
"zone_name": "STK",
"zone_no": "STK",
"status": "Your are checked-in and currently #1 STK. (as of: 7/19/2012 1:50:02 PM)",
"standby_list": [
{
"driver": "291",
"since": "12:33:00 PM",
"waiting": "77",
"gps_data": "0"
},
{
"driver": "103",
"since": "12:49:21 PM",
"waiting": "61",
"gps_data": "0"
},
{
"driver": "287",
"since": "12:51:00 PM",
"waiting": "59",
"gps_data": "0"
},
{
"driver": "271",
"since": "1:22:00 PM",
"waiting": "28",
"gps_data": "0"
},
{
"driver": "819",
"since": "8:58:36 AM",
"waiting": "292",
"gps_data": "1"
}
]
}
When I do this, the only last parse Json will show. Any ideas?
What do you mean by last JSON?
Are you referring to the last object in the JSONArray called “standby_list”?
If so, that’s because you are only keeping a handle on the last one.
Instead you should use some sort of collection and be calling Add on that.
For example