這裏是一個ArrayList(或目錄)全HashMaps這樣的:
ArrayList<HashMap<String, Object>> userNotifications = new ArrayList<HashMap<String, Object>>();
int count = 0;
HashMap<String, Object> notificationItem = new HashMap<String, Object>();
notificationItem.put("key1", "value1");
notificationItem.put("key2", "value2");
userNotifications.add(count, notificationItem);
count++;
然後檢索值:
ArrayList<HashMap<String, Object>> resultGetLast5PushNotificationsByUser = new ArrayList<HashMap<String, Object>>();
resultGetLast5PushNotificationsByUser = methodThatReturnsAnArrayList();
HashMap<String, Object> item1= resultGetLast5PushNotificationsByUser.get(0);
String value1= item1.get("key1");
String value2= item1.get("key2");
HashMap<String, Object> item1= resultGetLast5PushNotificationsByUser.get(1);
String value1= item1.get("key1");
String value2= item1.get("key2");
是您的數據總是JSON? – 2013-02-08 13:22:59
我不能使用JSON?不能以正常的方式做到這一點? – Goofy 2013-02-08 13:28:09
這個問題如何與Android相關? – iargin 2013-02-08 13:29:38