使用案例(把該函數放到App靜態類中) try { JSONObject result = new JSONObject(network.result); JSONArray bars = result.getJSONArray("bar"); barList.clear(); barIDs.clear(); for (int i = 0; i < bars.length(); i++) { JSONObject bar = bars.getJSONObject(i); String details = String.format(App.res.getString(R.string.bar_details), bar.getString("creator")); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("PostTitle", bar.getString("name")); map.put("PostContent", App.getJSONString(bar,"shortDescription")); map.put("PostDetails", details); barList.add(map); barIDs.add(bar.getInt("ID")); } adapter.notifyDataSetChanged(); ((ListView)findViewById(R.id.listView1)).setSelection(0); displayed = true; } catch (JSONException e1) { App.alert("JSONException"); e1.printStackTrace(); }
|