【发布时间】:2021-01-15 11:29:40
【问题描述】:
SetRawJsonValueAsync 的一些问题。当我使用文档中的代码时:
public class User
{
public string username;
public string email;
public User()
{
}
public User(string username, string email)
{
this.username = username;
this.email = email;
}
}
private void writeNewUser(string userId, string name, string email)
{
User user = new User(name, email);
string json = JsonUtility.ToJson(user);
mDatabaseRef.Child("users").Child(userId).SetRawJsonValueAsync(json);
}
然后 firebase 会自动将其转换为值树。好的。但是当我试图让他们回来时:
public void get_data()
{
mDatabaseRef.Child("users").Child(userId).GetValueAsync().ContinueWithOnMainThread(task => {
if (task.IsCompleted)
{
Debug.Log("completed");
string json = task.Result.Value;
User user = JsonUtility.FromJson<User>(json);
Debug.Log(user.username);
}
});
}
它停止并且不打印用户名。为什么?或者我需要如何获取 json raws?
【问题讨论】:
标签: c# firebase unity3d firebase-realtime-database