Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从云Firestore获取数据数组?_Java_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

Java 如何从云Firestore获取数据数组?

Java 如何从云Firestore获取数据数组?,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,这是我的密码: db.getFirestore().document("state/Madhya Pradesh/cities").get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { @Override public void onComplete(@NonNull Task<DocumentSnapshot> task) {

这是我的密码:

db.getFirestore().document("state/Madhya Pradesh/cities").get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
            DocumentSnapshot documentSnapshot=task.getResult();
        }
    });
db.getFirestore().document(“州/中央邦/城市”).get().addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
DocumentSnapshot DocumentSnapshot=task.getResult();
}
});

要从firestore获取阵列,请执行以下操作:-

DocumentReference documentReference = firestore.collection("states").document(uid);

documentReference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
    @Override
    public void onSuccess(DocumentSnapshot documentSnapshot){
        if(documentSnapshot.exists()){

            ArrayList<String> arrList = new ArrayList<String>();
            arrList = (ArrayList) documentSnapshot.get("cities");

            for(int i=0;i<arrList.size();i++){
                //Traversing the list
            }
        }
}
DocumentReference=firestore.collection(“states”).document(uid);
documentReference.get().addOnSuccessListener(新的OnSuccessListener()){
@凌驾
成功时公共无效(文档快照文档快照){
if(documentSnapshot.exists()){
ArrayList arrList=新的ArrayList();
arrList=(ArrayList)documentSnapshot.get(“cities”);

对于(inti=0;i请检查下面的代码。希望它能帮助您

  db.collection("Collection name").document("Document Id")
                        .collection("Collection name").get().addOnCompleteListener {
                            if (it.isSuccessful) {
                                if (it.result.isEmpty) {

                                  //List is empty
                                } else {
                                     val result = it.result.documents.map { it.toObject(YourModelClass::class.java)!! }
                                   //Performe array list operation
                                   // result is your array list
                                }
                            } else {
                                it.exception?.let {
                                   //Print exception
                                }
                            }
                        }

请检查副本以了解如何从Cloud Firestore数据库获取阵列。