Chartjs-How to get json response form http get request

0👍

I’m not sure I completely understand what your question / issue is, but I’ll give it a shot.

This code from your segment segment:

this.economicData = result;
console.log(this.economicData);
this.value = this.economicData.observations // other code here

Based on your console log screenshot this.economicData is an array. But, then you try to access a property on it, which I would expect to give an error.

0👍

Just look at my example. you have to install newtonsoft nuget package in order this code work.

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("API URL");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
    var inputs = new Parameters() { inputs }; // parameters is a class of your api input parameters
    HttpResponseMessage response = await client.PostAsJsonAsync("Continuation of your API URL", inputs);

    var resultString = await response.Content.ReadAsStringAsync();

    Excel resultJson = JsonConvert.DeserializeObject<your API Output Class>(resultString)!;

    if (response.IsSuccessStatusCode)
    {
        // your code after api response receive.
    }
    else
    {
        Console.WriteLine("Error");
    }
}

if this helped someone, pls upvote and accept this answer. thank you

Leave a comment