目前正在开发一个应用程序,其中用户可以检索firebase中的所有数据,但我目前很难,因为它需要一个特定的密钥来检索孩子。请帮我解决一下这个。提前谢谢你们:)
答案 0 :(得分:1)
如果要列出已检索的所有值,可以执行以下操作:
void HandleValueChanged(object sender, ValueChangedEventArgs args)
{
if (args.DatabaseError != null)
{
Debug.LogError(args.DatabaseError.Message);
return;
}
var livingRoomItems = args.Snapshot.Value as Dictionary<string, object>;
foreach (var item in livingRoomItems)
{
Debug.Log(item.Key); // Kdq6...
var values = item.Value as Dictionary<string, object>;
foreach (var v in values)
{
Debug.Log(v.Key + ":" + v.Value); // category:livingroom, code:126 ...
}
}
}
答案 1 :(得分:1)
大家遇到与我有同样问题的人,我已经找到了问题的答案:
void InitializeFirebase() {
FirebaseApp app = FirebaseApp.DefaultInstance;
app.SetEditorDatabaseUrl ("https://lol.firebaseio.com/");
FirebaseDatabase.DefaultInstance
.GetReference ("Products").OrderByChild ("category").EqualTo("livingroom")
.ValueChanged += (object sender2, ValueChangedEventArgs e2) => {
if (e2.DatabaseError != null) {
Debug.LogError (e2.DatabaseError.Message);
}
if (e2.Snapshot != null && e2.Snapshot.ChildrenCount > 0) {
foreach (var childSnapshot in e2.Snapshot.Children) {
var name = childSnapshot.Child ("name").Value.ToString ();
text.text = name.ToString();
Debug.Log(name.ToString());
//text.text = childSnapshot.ToString();
}
}
};
}