I have a service that gets the result in an API. API returns the results as JSON array. But I need the result as JSON object.
API returns:
[{"record_id":"101","demographics_spring_complete":"2"}]
I need as object format:
{"record_id":"101","demographics_spring_complete":"2"}
My service.ts:
getStatus() {
return this.http.post(this.baseUrl).map(res => res.json())
.catch(this.handleError);
}
And my conponent.ts:
export class BaselineListComponent implements OnInit {
statuses: any[] = [];
constructor(
public recordService: RecordsService
) { }
loadStatus() {
this.recordService.getStatus('demographic_spring', 'baseline_visit_a_arm_1', 101).subscribe(statuses => {
this.statuses = statuses;
console.log(this.statuses);
});
}
}
I did try some conversion options but since API returns an array, I am unable to convert them to a JSON object. Any help would be appreciated.