I have written these lines of code which make an API request and in return I get valid JSON response:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(_baseAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync(_apiUrl);
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadAsAsync<ExpandoObject>();
return Json(data);
}
}
The data
looks like below:
Is it possible to get the value of ProductID
and Price
. I want to assign them to something like:
int productId = ...
int price = ...
How can i do this using C#
?