我是 Android Kotlin 的新手,我想在我的物體中獲取 Firestore 中的一系列幫助,這是我的代碼:
val appCollection = App.context.db.collection("app")
val docApp = appCollection.document("info")
docApp.get().addOnCompleteListener { task ->
if (task.isSuccessful) {
val document = task.result
if (document.exists()) {
val list = document["help"] as List<*>?
}
}
}
我如何將該串列放入我的物體中,這是我的物體
class Info() : Parcelable{
var help: List<Help>? = null
var howto: List<HowTo>? = null
var info: List<Info>? = null

uj5u.com熱心網友回復:
正如我在您的螢屏截圖中看到的,您的help陣列包含 String 型別的物件而不是type 的物件Help。要讀取這樣的陣列,請更改以下欄位宣告:
var help: List<Help>? = null
到:
var help: List<String>? = null
但是,如果您需要存盤Help在陣列中,則需要先相應地添加此類物件。所以你的結構可能是這樣的:
Firestore-root
|
--- app (collection)
|
--- info (document)
|
--- help (array)
|
--- 0
|
--- fieldOne: valueOne
|
--- fieldTwo: valueOTwo
要將這樣的陣列映射到自定義物件串列,請查看以下文章:
- 如何將物件陣列從 Cloud Firestore 映射到物件串列?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/411486.html
標籤:
