How to get the Key from data snapshot in Firebase unity c#?

若如初见. 提交于 2020-07-23 07:03:05

问题


I am trying to build a game using Unity and Firebase SDK. I want to get the key of circles in the image.

    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...
          }
      });

I get the key as "live_games" not "0"


回答1:


Thanks Doug Stevenson it worked

    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...
          }
      });


来源:https://stackoverflow.com/questions/61716598/how-to-get-the-key-from-data-snapshot-in-firebase-unity-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!