如何从Firebase Unity C#中的数据快照获取密钥? [英] How to get the Key from data snapshot in Firebase unity c#?

查看:97
本文介绍了如何从Firebase Unity C#中的数据快照获取密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我得到的密钥是"live_games"而不是"0"

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

推荐答案

感谢道格·史蒂文森(Doug Stevenson)起作用

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

这篇关于如何从Firebase Unity C#中的数据快照获取密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆