So I’m Calling a Web API From a ASP.NET core application. Im using HttpClient and reading it in as a string but i want to read it as a JSON object. I'm aware that that you can read it as Generic class ReadAsAsync<Generic>();
However, the returning object is a massive JSON object and it would be to much work to write a Generic class for it. My question is how can i just read it as its JSON object ?
public async Task<IActionResult> SendRequest()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(" https://api.forecast.io/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// HTTP GET
HttpResponseMessage response = await client.GetAsync("forecast/KEY/");
if (response.IsSuccessStatusCode)
{
var forcast = await response.Content.ReadAsStringAsync();
Console.WriteLine("{0}", forcast);
// return Json( JSON ) ;
}
}
// return Json( JSON ) ;
}
I see Three types of response readers, can any of these become JSON objects ?
ReadAsByteArrayAsync, ReadAsStreamAsync, ReadAsStringAsync