get data from firestore firebase

2019-04-11 07:23发布

i need to get the data of formName and id from the following data Structure in firestore. how to get data in this case like nested objects are created?

enter image description here

2条回答
成全新的幸福
2楼-- · 2019-04-11 07:31

Nested values translate to maps in Java, so something like this should to do the trick:

DocumentReference docRef = db.collection("employees").doc("JdkK...");
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
    @Override
    public void onSuccess(DocumentSnapshot documentSnapshot) {
        Map<String, Object> forms = documentSnapshot.get("dynForms");
        for (Map.Entry<Object, Object> form: forms.entrySet()) {
            String key = (String) form.getKey();
            Map<Object, Object> values = (Map<Object, Object>)form.getValues();
            String name = (String) values.get("formName");
        }
    }
})
查看更多
叛逆
3楼-- · 2019-04-11 07:50

You can apply binding techniques to map the objects/array/variables. For this you can use jackson 2 or gson. For example on jackson 2 usage see reference: https://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/

查看更多
登录 后发表回答