使用Cloud Firestore从单个文档中获取列表对象

时间:2018-07-07 19:19:47

标签: java android google-cloud-firestore

我在Firestore的单个文档中有对象存储的列表。在我的Android方面,我无法提取对象及其内部数据的列表。

这是我要提取数据的代码

        CollectionReference mCollectionReference = FirebaseFirestore.getInstance().collection("Categories");

mCollectionReference.document("Dinner Dishes").get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
    @Override
    public void onSuccess(DocumentSnapshot documentSnapshot) {

        Collection<Object> objectMap = documentSnapshot.getData().values();

        for(Object result:objectMap){
            Sample obj = Sample.class.cast(result);
            HashMap<String, String> pic = obj.getPic();
            HashMap<String, String> name = obj.getName();
        }
    }
});

我需要在Firestore中以单个文档上传的对象列表

我的模型班:

    public class Sample {

    private String name;
    private String pic;

    public Sample() {
    }

    public String getName() {
        return name;
    }

    public String getPic() {
        return pic;
    }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以将其转换为Java对象吗?

ObjectType myObject = document.toObject(ObjectType.class);