Android-Expected a List while deserializing, but got a class java.util.HashMap

后端 未结 5 1083
小蘑菇
小蘑菇 2021-01-18 23:07

I want to get all list of restaurants from Firebase in android.

Here is my code:

boolean delivery;
String openTime, closeTime, restaurantName;
long          


        
5条回答
  •  离开以前
    2021-01-18 23:25

    Kotlin Example
    This is a example to get all your nested data out of firebase real time database.

    There are many tokens in this example and every token contains list of notes

     val noteListener = object : ValueEventListener {
    
                override fun onDataChange(dataSnapshot: DataSnapshot) {
                    // For each loop will run until all notes are fetched
                   for (snapshot in dataSnapshot.children){
                       val note = snapshot.getValue(Note::class.java)
                       Log.e("Note",note?.title)
                   }
                }
    
                override fun onCancelled(databaseError: DatabaseError) {
                    // On failed, log a message
                    Log.e("Debug", "loadPost:onCancelled", databaseError.toException())
                }
            }
    
            //You can use the addListenerForSingleValueEvent() method to simplify this scenario: it triggers once and then does not trigger again.
            //ref.child(token) is the path for reach notes for each unique user , in your case it can be ref only
            ref.child(token).addListenerForSingleValueEvent(noteListener)
    

提交回复
热议问题