有人可以幫助指導我如何解析JSONArray的成TextViews?到目前爲止,每次我解析它時,它都只顯示最後的結果,而不是一切。解析JSONArray到TextView的
到目前爲止,我有:
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();
}
我試圖做的事:
TextView information = (TextView) findViewById(R.id.information);
information.setText (DRIVER + SINCE + WAITING);
這裏就是我試圖解析:
{
"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"
}
]
}
當我這樣做,這是Json唯一的最後解析。有任何想法嗎?
很抱歉這麼晚纔回復弗蘭克,我想你可能將要發生什麼,但我將如何把這個在TextView的,而不是ArrayList的? – 2012-07-20 15:40:38
那麼你將不得不從你的ArrayList中選擇1項來填充你的TextViews。如果您試圖在屏幕上顯示所有對象,那麼您可能會想要使用ListView。然後你將你的ArrayList傳遞給你的ListViewAdapter,並且會負責顯示每一個。但是,這是一個完全不同的話題。 – 2012-07-20 16:03:21