简体   繁体   中英

unity firebase database retrieving data

how to get the proper way or ShortCut or fastest way retrieving data of particular child from the firebase

baseRef.Child ("wordRun").Child("Players").Child(userid).Child("GameRun").Child("usercount").GetValueAsync ();

I try like something:- example 1

var getTask =baseRef.Child ("wordRun").Child("Players").Child(userid).Child("GameRun").Child("usercount").GetValueAsync ();

        yield return new WaitUntil(() => getTask.IsCompleted || getTask.IsFaulted);

        if (getTask.IsCompleted) {
            Debug.Log(getTask.Result.Value.ToString());
        }

example 2:-

baseRef.Child("wordRun").Child("Players").Child(userid).Child("GameRun").Child("usercount").GetValueAsync .ContinueWith(task => {
                    if (task.IsFaulted) {
                        // Handle the error...
                    }
                    else if (task.IsCompleted) {
                      DataSnapshot snapshot = task.Result;
                      foreach ( DataSnapshot user in snapshot.Children){
                        IDictionary dictUser = (IDictionary)user.Value;
                        Debug.Log ("" + dictUser["usercount"]);
                      }
                    }
          });

I want to get values write a single line in firebase database if anyone knew how got value in a single line in firebase then please give answer thank you for reading...

And Please Give me a way to get all data back in a class by getting GetRawJsonValue

you need to getting by the loop

foreach (var childSnapshot in args.Children) { 

Debug.Log("ChildSnapshot"+childSnapshot..GetRawJsonValue());

} 

and if you have any Class which have same data format then you try this

ClassName ClassObjectName = JsonUtility.FromJson<ClassName>(args.Snapshot.GetRawJsonValue());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM