Previously ,我要求获取firebase中的数据。但我无法获取该值...我的数据库是这样的。
{Singer :
{Eminem :
{01 :
songName : "Rap god",
songType : "type01"
},
{02 :
songName : "Till I collapse",
songType : "type02"
}
},
{Lauv :
{01 :
songName : "I Like Me Better",
songType : "type01"
},
{02 :
songName : "lonely",
songType : "type03"
}
},
{Alan Walker :
{01 :
songName : "All Falls Down",
songType : "type02"
},
{02 :
songName : "On My Way",
songType : "type01"
}
}
}
我想获取全部type01
在Singer
他们全部。我尝试过这样的代码
@Override
public void onBindViewHolder(@NonNull MyHolder holder, int i) {
...
Query myQuery = FirebaseDatabase.getInstance().getReference().child("Singer").orderByChlid("songType").equalsTo("type01");
FirebaseRecyclerOption.Builder<ItemModel>.setQuery(myQuery, new SanpshotParser<ItemModel>() {
@NonNull
@Override
public ItemModel parseSnapshot(@NonNull DataSnapshot snapshot) {
String songStr = snapshot.child("songName").getValue().toString();
String typeStr = snapshot.child("songType").getValue().toString();
return new ItemModel(songStr, typeStr);
}
}).build();
...
}
但我无法得到我想要的东西。 FirebaseDatabase.getInstance().getReference().child("Singer").orderByChild("songType").equalsTo("type01")
无法读取函数parseSnapshot
中的数据。如何获取输入为type01
的歌手的所有歌曲?
最佳答案
您需要更深入一步,以便查询可以访问songType
:
FirebaseDatabase.getInstance().getReference().child("Singer").child("Eminem").orderByChild("songType").equalsTo("type01")
关于java - 如何使用 android 获取 Firebase 数据库中的子值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58090533/