android - 如何从Android中的Cloud Firestore获取集合内的对象列表?

标签 android firebase kotlin google-cloud-firestore

Here's the data

我如何获得“listTask”

我尝试使用以下代码记录“document.data [“listTask”]“:

db.collection("project").get()
        .addOnSuccessListener { result ->
            Log.d(TAG, "onRefresh: loadProject")
            for (document in result){
                if (document.data["owner_id"]== id){
                    counter++
                    Log.d(TAG, "inside response: ${document.data["listTask"]}")
                }
            }

        }

这是日志结果
D/YourProjectFragment: inside response: [{id=29356, title=Database, status=false}, {id=28581, title=UI UX, status=false}, {id=66044, title=Architecture Design, status=false}, {id=77830, title=Functional Test, status=false}]

我不知道响应的模式,我尝试了JSONArray,但不是JSONArray

那么如何获取Cloud Firestore中集合内部的对象列表?

最佳答案

I have tried with jsonArray but that is not jsonArray



显然,这不是JSONArray,而是对象类型的属性。除此之外,JSONArray不是supported data type

So how to get the list of objects inside a collection in Cloud Firestore?



不幸的是,您不能将listTask属性直接映射到自定义对象列表中。您应该为此编写一些代码。 listTask属性实际上是HashMap对象的列表,作为您的响应状态:
response: [{id=29356, title=Database, status=false}, {id=28581, title=UI UX, status=false}, {id=66044, title=Architecture Design, status=false}, {id=77830, title=Functional Test, status=false}]

看,它以[开头,以]结束,这使它成为一个数组,并且该数组中的每个对象都是HashMap。因此,您需要遍历此HashMap对象列表,并创建自己的"Task"对象列表。

如果需要,可以联系Firebase团队提出要求。

关于android - 如何从Android中的Cloud Firestore获取集合内的对象列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60753246/

相关文章:

android - AWS Android SDK 连接超时和重试

java - 如何通过另一个方法访问一个方法?

快速 Firebase 存储 NSInternalInconsistencyException

ios - 当我尝试将数据保存到 Firebase 时,它​​只会更新现有数据、Swift、Firebase

spring-boot - 在 Kotlin 中迁移到版本 3+ 时,Spring Boot 无法再绑定(bind)配置属性

java - API 'variant.getJavaCompile()' 已过时

android - 如何在 Box2D 中创建动态物体?

android - ImageView 不显示某些图像

javascript - 在 firebase 中计算点赞数

android - 更新到 WorkManager 1.0.0-alpha09 后编译错误