Angular 2 Http get - parsing JSON object from response

Viewed 16503

I am trying to parse a JSON object that my server API returns after making an HTTP get request to it. Here is the call to the Http

getPayoutReport(param1, param2, param3) {

    //do some hanky panky
    //configure a requestUrl
    return this.http.get(this.requestUrl).map((res:Response)=> res.json());

}

Here is the receiver method:

this.payoutReportsService.getPayoutReport(this.reservationId, this.productId, this.vendor)
        .subscribe(data => {this.payoutReport = data; console.log(this.payoutReport);});

When I log this.payoutReport, I can see a JS Object object in the console. When I examine it in the console, I can see that this has all the properties of the JSON object I need (basically this is the object I need). Except that it is a JS Object object, not the JSON object format I am looking for.

I tried:

 return this.http.get(this.requestUrl).map(this.extractData);
 private extractData(res: Response) {
    let body = res.json();
    return body.data || { };
}

But then, res.json().data is undefined, and it returns an empty object.

Help appreciated!

2 Answers
Related