C# - FireSharp Firebase Database can't retrieve data

2

I've been trying to retrieve all the data from the Firebase Database using the FireSharp on Windows Forms App, I want to convert it into the custom List, but when I do, it gives me an exeption.

I tried almost everything possible, my goal is to get data like this:

Users: 12345: name: "George" surname: "Gigauri" 234213: name: "Nika" surname: "Gigauri"

as:

12345, 234213 so I would retrieve their objects (like name, surname) later. I'm using the code:

private async void checkUser()
        {
            FirebaseResponse response = await client.GetAsync("Users");
            List<Data> list = JsonConvert.DeserializeObject<List<Data>>(response.ToJson());
        }

And it gives me an exception:

Newtonsoft.Json.JsonSerializationException
  HResult=0x80131500
  Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[ConnectServer.Data]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'Body', line 1, position 8.
  Source=Newtonsoft.Json
  StackTrace:
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at ConnectServer.Form1.<checkUser>d__10.MoveNext() in D:\Microsoft Visual Studio\Projects\ConnectServer\ConnectServer\Form1.cs:line 101
c#
.net
windows
winforms
firebase
asked on Stack Overflow May 25, 2019 by user8141203

1 Answer

0

here is an example to retrieve multi nodes as Jason format and serializing result for populating in like control Datagridview control

Counter_class  XClass = new Counter_class();                
FirebaseResponse firebaseResponse = await client.GetAsync("Counter/node");
string JsTxt = response.Body;
                if (JsTxt == "null")
                {

                    return ;
                }

 dynamic data = JsonConvert.DeserializeObject<dynamic>(JsTxt);
                var list = new List<XClass >();
                foreach (var itemDynamic in data)
                {
                  list.Add(JsonConvert.DeserializeObject<XClass > 
                  (((JProperty)itemDynamic).Value.ToString()));
                }
             // Now you have a list  you can loop through to put it at any suitable Visual  
            //control 
                foreach ( XClass  _Xcls in list)
                {
Invoke((MethodInvoker)delegate {
                            DataGridViewRow row(DataGridViewRow)dg.Rows[0].Clone();
                            row.Cells[0].Value =_Xdcls...
                            row.Cells[1].Value =Xdcls...
                            row.Cells[2].Value =Xdcls...
                            ......
                            dg.Insert(0, row); 

}

Also see my answer on this thread : How to add data from Firebase to DataGridView using FireSharp

answered on Stack Overflow Dec 24, 2019 by Isaac Be

User contributions licensed under CC BY-SA 3.0