问题
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