0

I am trying to get data from firebase but it shows an error "Could not cast or convert from System.String to System.Collections.Generic.Dictionary`2"

This is my code:

IFirebaseConfig config = new FirebaseConfig()
    {
        AuthSecret = "Auth",
        BasePath = "Path"
    };
    IFirebaseClient client;

    private void Form1_Load(object sender, EventArgs e)
    {
        try
        {
            client = new FirebaseClient(config);
            if (client != null)
            {
                MessageBox.Show("OK");
            }
        }
        catch
        {
            MessageBox.Show("No");
        }
        LiveCall();
    }
    async void LiveCall()
    {

        while (true)
        {
            await Task.Delay(1000);
            FirebaseResponse res = await client.GetAsync(@"GPS/lat");
            Dictionary<string, GPS> data = JsonConvert.DeserializeObject<Dictionary<string, GPS>>(res.Body.ToString());
            UpdateRTB(data);
        }
    }
    void UpdateRTB(Dictionary<string, GPS> record)
    {
        label1.Text += record.ElementAt(1).Key + record.ElementAt(1).Value;
    }

Can Anybody help me to solve the problem? thanks!

Jeff Li
  • 3
  • 1
  • What kind of serialization are you expecting? – Abhishek Dutt Oct 01 '22 at 14:13
  • 1
    I think I want to change the json to string – Jeff Li Oct 01 '22 at 14:17
  • What library is `FirebaseClient` from? Is it [`FirebaseClient.cs`](https://github.com/ziyasal/FireSharp/blob/master/FireSharp.Core/FirebaseClient.cs) from [FireSharp](https://github.com/ziyasal/FireSharp)? – dbc Dec 13 '22 at 18:54
  • Also, at what line do you get the error? Can you share a full [mcve] showing the `GPS` class as well as the value of `res.Body.ToString()`? – dbc Dec 13 '22 at 18:56

0 Answers0