Android 无法创建调用,正在尝试通过改装将我的firebase数据库提取到recyclerview中
甚至在Firebase+改型上找不到一些有用的资源(与Android其他方面的大量教程相反)。第一次使用Firebase时,我导入了一个json:Android 无法创建调用,正在尝试通过改装将我的firebase数据库提取到recyclerview中,android,firebase,kotlin,firebase-realtime-database,retrofit,Android,Firebase,Kotlin,Firebase Realtime Database,Retrofit,甚至在Firebase+改型上找不到一些有用的资源(与Android其他方面的大量教程相反)。第一次使用Firebase时,我导入了一个json: {"Qoutes" :[ { "quote":"I\u2019m sure you are tired counting the years of your age. May these years be endless and full of happiness!",
{"Qoutes" :[
{
"quote":"I\u2019m sure you are tired counting the years of your age. May these years be endless and full of happiness!",
"relation":"grandmother"
},
{
"quote":"My sweet Grandma, I wish you to be always happy and healthy as today! Happy birthday my beloved old woman!",
"relation":"grandmother"
},
{
"quote":"May you stay healthy and happy for the years to come. We are all happy to have you here with us!",
"relation":"grandmother"
},
.
.
.
]}
愿望班
data class Wish(
@SerializedName("quote")
val quote: String?,
@SerializedName("relation")
val relation: String?
)
APIService接口
interface APIService {
@GET("Qoutes")
suspend fun getQuotes(): Response<Wish>
}
存储库
class Repository @Inject constructor() {
suspend fun getWishes(): Response<Wish> {
return RetrofitInstance.api.getQuotes()
}
}
我希望在某个地方这是一个无意义的错误,因为这对我来说都是新鲜的,而且阅读所有的课程也不太麻烦。提前感谢大家的阅读
另外,我知道我在json中写的引号是错误的,所以我在其他地方写的都是错误的:D你在这里尝试的是通过它访问Firebase实时数据库。为了确保这一点,您需要以
.json
因此:
请注意,可能存在多个问题,但这肯定是其中之一
class Repository @Inject constructor() {
suspend fun getWishes(): Response<Wish> {
return RetrofitInstance.api.getQuotes()
}
}
private val repository: Repository
): ViewModel() {
var myResponse: MutableLiveData<Response<Wish>> = MutableLiveData()
fun getQuotes() {
viewModelScope.launch {
val response: Response<Wish> = repository.getWishes()
myResponse.value = response
}
}
viewModel.getQuotes()
viewModel.myResponse.observe(viewLifecycleOwner, { response ->
if(response.isSuccessful)
Log.d("Response ->", response.body().toString())
else
Log.d("Response ->", response.errorBody().toString())
Retrofit.Builder()
.baseUrl("https://birthdayzheimer-default-rtdb.firebaseio.com/.json")