When attempting to retrieve a string from a JSON response, I encounter an error:
SyntaxError: Unexpected token c in JSON at position
In the controller, a GUID is returned as a string from the database:
[HttpPost("TransactionOrderId/{id}")]
public async Task<string> TransactionOrderId(int id)
{
return await this._service.GetTransactionOrderId(id);
}
In my Angular 2 application, there is an issue with parsing the server's response when subscribing to the provider:
this.meetingsProvider.getTransactionOrderId(this.meetingId).subscribe((transactionId: string) => {
this.transactionOrderId = transactionId;
});
The provider code is as follows:
getTransactionOrderId(meetingId: number): Observable<string> {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(`${this.apiUrl}/${this.route}/transactionOrderId/${meetingId}`, null, {
headers: headers
}).map(res => <string>res.json());
}
Upon receiving the transaction order ID response from the server, the format appears as:
status: 200
statusText: "OK"
type: 2
url: "http://localhost/api/meetings/transactionOrderId/4"
_body: "0c290d50-8d72-4128-87dd-eca8b58db3fe"
While other API calls using similar code to return boolean values work fine, attempting to return a string triggers a parsing error. Why does this happen?