且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将所有字段名称从 firestore 文档获取到数组列表

更新时间:2023-02-18 22:57:18

要打印这些属性名称,请使用以下代码:

To print those property names, please use the following code:

FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
DocumentReference codesRef = rootRef.collection("CodeClinic").document("Codes");
codesRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<DocumentSnapshot> task) {
        if (task.isSuccessful()) {
            List<String> list = new ArrayList<>();
            Map<String, Object> map = task.getResult().getData();
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                list.add(entry.getKey());
                Log.d("TAG", entry.getKey());
            }
            //Do what you want to do with your list
        }
    }
});

输出将是:

Clinica
FEUP
outra