首页 > 解决方案 > 如何从 Firebase unity c# 中的数据快照获取密钥?

问题描述

我正在尝试使用 Unity 和 Firebase SDK 构建游戏。我想获得图像中圆圈的关键。

在此处输入图像描述

    FirebaseDatabase.DefaultInstance
      .GetReference("live_games")
      .OrderByChild("gameId").EqualTo(GAME_KEY)
      .GetValueAsync().ContinueWith(task => {
          if (task.IsFaulted)
          {
              // Handle the error...
          }
          else if (task.IsCompleted)
          {
              DataSnapshot snapshot = task.Result;
              Debug.Log("the json " + snapshot.GetRawJsonValue());
              Debug.Log("the key is "+ snapshot.Key);
              // Do something with snapshot...
          }
      });

我得到的钥匙是“live_games”而不是“0”

标签: c#firebaseunity3dfirebase-realtime-database

解决方案


谢谢道格史蒂文森它工作

    FirebaseDatabase.DefaultInstance
      .GetReference("live_games")
      .OrderByChild("gameId").EqualTo(GAME_KEY)
      .GetValueAsync().ContinueWith(task => {
          if (task.IsFaulted)
          {
              // Handle the error...
          }
          else if (task.IsCompleted)
          {
              DataSnapshot snapshot = task.Result;
              foreach(var child in snapshot.Children)
              {
                  Debug.Log("The Key"+child.Key);
              }
              // Do something with snapshot...
          }
      });

推荐阅读