0

Im not quite sure how to go about deserializing the list i'm retrieving from my firebase database.

The fetch:

 var x = (await firebase
                .Child(ChildName)
                .OnceAsync<Userlogin>()).Select(item =>
                new Userlogin
                {
                    user_login = item.Object.user_login,
                    passwords = item.Object.passwords
                }).ToList();

The error im getting:

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.

The Error is rather Self explanatory Im just not sure how to approach it, using the current method as its already going to a list so im just not sure

I tried something like :

  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;
            }

        }

1 Answers1

0

At first, please make sure the ChildName in the Child(ChildName) is the table name in the database.

And then, you can check this case which has the same error and the problem is the structure of the data.

In addition, you can try the following code if you use (item => new Userlogin{ }).ToString();

datalist = JsonConvert.DeserializeObject<Dictionary<string, Userlogin>>(content).Values.ToList()
Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14