1

Firebase database

For this i want to get all the vehicles as a list of vehicle objects

FirebaseResponse response = await client.GetAsync("Vehicles/");
List<Data> vehicles = response.ResultAs<List<Data>>().ToList();

this gives a JSON serialization exception. The data class is as follows:

internal class Data
{
    public string tag { get; set; }
    public string vehicleNo { get; set; }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Yomal
  • 362
  • 2
  • 15

2 Answers2

2

See a solution here

var mList= JsonConvert.DeserializeObject<IDictionary<string, Match>>(jsonstr);
0

So we create a dictionary, its basically a Map of Id of the object to the object itself for every entry in the snapshot. We are using a deserializer from the Newton package.

Dictionary<string, Data> = JsonConvert.DeserializeObject<Dictionary<string, Data>>(response.Body.ToString()) ?? new();