I have simple method in aspnet web api with following test results:
$ curl localhost:5000/Api/GetAllQuestions
[{"questionId":0,"value":"qqq","answers":[{"answerId":25,"value":"qwerty"}]}]
In angular2 http service something is wrong:
GetQuestions(): Observable<Question[]> {
return this.http.get("Api/GetAllQuestions")
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
console.log(res.json()[0]);
return body.data || {};
}
because it returns {} every time, but in console log I have some expected results:
Object { questionId: 0, value: "qqq", answers: Array[1] }
What am I doing wrong, and how can I parse JSON successfully?