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 notjsonArray
显然,这不是
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/