我的firestore中有下面的結構,我想讀取數據并將其存儲在arraylist中,就像我有“amountArrayList”從firestore的“transactions”字段讀取數據一樣,我想從“Transactices”字段讀取所有“amount”字段,并制作其數組列表,以便我可以以列表方式顯示它。
My code
Map<String, Object> map = document.getData();
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getKey().equals("transactions")) {
System.out.println(entry.getValue().toString());
}
}
Output
[{transactionType=Credit,amount=3000,dateToStr=2021 12月17日,timeToStr=08:06:10,description=},{TransmationType=Credit,amount=2000,dateToStr=2021 12月17號,timeToStr=08:06:50,Descriptions=}]
因為
transactions
是一個數組字段,所以從entry.getValue()
得到的值是對象的List
。因為JSON中的每個對象都有屬性,所以它們在Java代碼中都將是Map<String, Object>
。打印金額的簡單方法如下: