store 存取数据数组对象_如何从Firestore文档中获取对象数组
我在Firestore中有一個如下所示的數據結構:
父POJO是:public class Restaurant {
private Double distance;
private GeoPoint geoPoint;
private int distributionType;
private List dailyHours;
public Restaurant(Double distance, GeoPoint geoPoint, int distributionType, List dailyHours) {
this.distance = distance;
this.geoPoint = restaurantLogo;
this.restaurantDescription = distributionType;
this.dailyHours = dailyHours;
}
// Getter & Setter (excluded most for the sake of clarity
public List getDailyHours() {
return dailyHours;
}
public void setDailyHours(List dailyHours) {
this.dailyHours = dailyHours;
}
}
然后是DailyHours POJO:public final class DailyHours {
boolean selected;
String thisDay;
int startHour;
int closeHour;
public DailyHours(boolean selected, String thisDay, int startHour, int closeHour) {
this.selected = selected;
this.thisDay = thisDay;
this.startHour = startHour;
this.closeHour = closeHour;
}
// Setter and Getter
}
我如何將它放入一個數組中(其中會有一個數組)?
我正在嘗試這樣做(其中restaurantArrayList是Restaurant對象的數組):db.collection("database").get().addOnSuccessListener(queryDocumentSnapshots -> {
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
Restaurant restaurant = documentSnapshot.toObject(Restaurant.class);
restaurantArrayList.add(restaurant);
}
}
并最終得到以下錯誤:
無法反序列化對象。 類com.eataway.partner.Models.DailyHours未定義無參數構造函數。 如果您正在使用ProGuard,請確保這些構造函數沒有被剝離(在字段'daily hours.[0]'中找到)
我想我必須解析對象數組,但我不知道如何做。 請指教。
總結
以上是生活随笔為你收集整理的store 存取数据数组对象_如何从Firestore文档中获取对象数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: USTC English Club No
- 下一篇: USTC English Club No