I'm getting a data from API and converting it to json string as follows -
[HttpGet]
public async Task<JProperty[]> GetSomeDataAsync()
{
try
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("myURI");
HttpResponseMessage response = await client.GetAsync(client.BaseAddress);
response.EnsureSuccessStatusCode();
//string responseBody = await response.Content.ReadAsStringAsync();
if (response != null)
{
jsonString = await response.Content.ReadAsStringAsync();
jsonObject = JObject.Parse(jsonString);
//return JsonConvert.DeserializeObject(jsonString);
//return JsonConvert.DeserializeObject<object>(jsonString);
var x = jsonObject.Descendants().OfType<JProperty>().Where(p => p.Name == "observations")
.ToArray();
return x;
}
else
{
throw new ArgumentNullException();
}
}
catch (Exception ex)
{
}
The above code is written in Controller and response is sent to Angular Component which contains the following code -
public economicData: any | null = null;
public value: any;
chart: any=[];
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string)
{
http.get<any>(baseUrl + 'somedata', { context: new
HttpContext().set(IsCacheable, true)
}).subscribe(result => {
this.economicData = result;
console.log(this.economicData);
this.value = this.economicData.observations.map((observations:
any) => {
observations.value });
console.log(this.value);
}, error => console.error(error));
}`
I'm able to see data in array during debug mode in controller. But I'm not getting any data in the objects array in console log nor in the result of component while debugging. Hence I'm not able to map the property present in json to the chart.
Following is the image of output logged in console.log- enter image description here