[英]How to deserialize firebase fetch
我不太確定如何反序列化我從我的 firebase 數據庫中檢索的列表。
獲取:
var x = (await firebase
.Child(ChildName)
.OnceAsync<Userlogin>()).Select(item =>
new Userlogin
{
user_login = item.Object.user_login,
passwords = item.Object.passwords
}).ToList();
我得到的錯誤:
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
錯誤是不言自明的,我只是不確定如何處理它,使用當前方法,因為它已經進入列表,所以我不確定
我嘗試了類似的東西:
public async Task<List<Userlogin>> GetAllUser()
{
try
{
var x = (await firebase
.Child(ChildName)
.OnceAsync<Userlogin>()).Select(item =>
new Userlogin
{
user_login = item.Object.user_login,
passwords = item.Object.passwords
}).ToString();
List<Userlogin> datalist = JsonConvert.DeserializeObject<List<Userlogin>>(x);
return datalist;
}
catch (Exception e)
{
Console.WriteLine(e);
Crashes.TrackError(e);
return null;
}
}
首先,請確保Child(ChildName)
中的 ChildName 是數據庫中的表名。
然后,您可以檢查這個具有相同錯誤的案例,問題是數據的結構。
另外,如果使用(item => new Userlogin{ }).ToString();
可以試試下面的代碼
datalist = JsonConvert.DeserializeObject<Dictionary<string, Userlogin>>(content).Values.ToList()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.