SyntaxError: Unexpected token C in JSON at position 0 - Ionic 2 Http GET request

Viewed 50605

I am trying to perform a GET request and retrieve the data from the response.

this.http.get('http://localhost:8888/maneappback/more-items.php').subscribe(res => {
    console.log(res.json());
}, (err) => {
    console.log(err);
});

I am getting the error SyntaxError: Unexpected token C in JSON at position 0. I am also assuming that the error is related to the request.

On my server side, I have the data being sent like this (PHP):

echo json_encode($array);

3 Answers

in my case:

previous with error: JSON.parse("{ createdTimestamp: -1 }")

and correct: JSON.parse('{"createdTimestamp":-1}')

Related