Unity&中的RawJsonValues火力基地 [英] RawJsonValues in Unity & Firebase
本文介绍了Unity&中的RawJsonValues火力基地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SetRawJsonValueAsync
的某些问题.当我使用文档中的代码时:
Some problems with the SetRawJsonValueAsync
. When I use the code from documentation:
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自动将其转换为值树.好的.但是当我试图让他们回来时:
Then firebase automatically converts it to the tree of values. Ok. But when i'm trying to get them back:
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原始数据?
it stops and doesn't print username. Why? Or how i need to get json raws?
推荐答案
此处的问题是您想要的是 task.Result.GetRawJsonValue()
:
What you want is task.Result.GetRawJsonValue()
:
public void get_data()
{
mDatabaseRef.Child("users").Child(userId).GetValueAsync().ContinueWithOnMainThread(task => {
if (task.IsCompleted)
{
Debug.Log("completed");
string json = task.Result.GetRawJsonValue();
User user = JsonUtility.FromJson<User>(json);
Debug.Log(user.username);
}
});
}
这篇关于Unity&中的RawJsonValues火力基地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文