[英]Loading a dictionary of lists of lists in Unity with Firebase
So im saving my Dictionary like this:所以我像这样保存我的字典:
public void saveData()
{
database.Child("Users").Child("User").SetValueAsync(shoppingList);
}
But if I want to load my dictionary it always returns null when I want to access anything.但是,如果我想加载我的字典,当我想访问任何内容时,它总是返回 null。 I load it like this:
我像这样加载它:
public void loadData()
{
FirebaseDatabase.DefaultInstance.GetReference("Users").GetValueAsync().ContinueWith(task => {
if (task.IsFaulted)
{
// Handle the error...
}
else if (task.IsCompleted)
{
var result = task.Result;
var loadedDict = result.Value as Dictionary<string, List<List<string>>>;
Debug.Log(loadedDict);
}
});
}
I think what might be happening is that the var loadedDict = result.Value as Dictionary<string, List<List<string>>>;
我认为可能发生的情况是
var loadedDict = result.Value as Dictionary<string, List<List<string>>>;
is not making the conversion rightaway.没有立即进行转换。
I would check the following.我会检查以下内容。
1.- That the data is being properly saved in the save stage, and stored in the database and confirm that in the question. 1.-数据在保存阶段正确保存,并存储在数据库中并在问题中确认。
2.- Even the dictionary is null, check if the data returned from the task is null. 2.-即使字典是null,检查任务返回的数据是否是null。 Because the data might be being retrieved in the
var result = task.Result;
因为可能正在
var result = task.Result;
中检索数据, but the conversion to the dictionary not working. ,但转换为字典不起作用。 I would also confirm that in the question if that is the case.
如果是这种情况,我也会在问题中确认这一点。
3.- If the data is actually being retrieved in stage 2, and what is not working is the conversion. 3.- 如果数据实际上是在第 2 阶段检索的,而转换不起作用。 As far as the documentation says, the values returned native types are:
据文档所述,返回本机类型的值是:
bool
, string
, long
, double
, IDictionary{string, object}
and List{object}
bool
, string
, long
, double
, IDictionary{string, object}
和List{object}
If you are receiving the data but the loadedDict
is null, you will need to code the method that converts the IDictionary{string, object}
to your Dictionary<string, List<List<string>>>
with your info filled in.如果您正在接收数据,但加载的字典是
loadedDict
,您需要编写将IDictionary{string, object}
转换为Dictionary<string, List<List<string>>>
的方法,并填写您的信息。
I did not use firebase with unity, only in web projects, so I am not sure if this might by your problem, is just my guess.我没有统一使用 firebase,仅在 web 项目中使用,所以我不确定这是否可能是您的问题,这只是我的猜测。 I'll be glad to check what you find out
我很高兴检查您的发现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.