0

I have an angular project and I have the following error:

ERROR SyntaxError: Unexpected end of JSON input
        at JSON.parse (<anonymous>)
        at Response.Body.json (http.js:1091)
        at SafeSubscriber.eval [as _next] (home.component.ts:57)
        at SafeSubscriber.__tryOrUnsub (Subscriber.js:243)
        at SafeSubscriber.next (Subscriber.js:190)
        at Subscriber._next (Subscriber.js:131)
        at Subscriber.next (Subscriber.js:95)
        at MapSubscriber._next (map.js:85)
        at MapSubscriber.Subscriber.next (Subscriber.js:95)
        at XMLHttpRequest.onLoad (http.js:1591)

in the chrome console. (home.component.ts:57):

  getBooks() {
    const promise = this._homeService.getBooks();
    promise.subscribe(
      data => {
        var jsonObject = data.json();
        console.log(jsonObject);
        this.books = jsonObject;
      },
      error => {
        console.log(error);
      });
  }

the line 57 is

var jsonObject = data.json();

can anybody help me please..

1 Answer 1

1
  1. It's very confusing that you name your observable as promise.

  2. I guess you don't need to data.json(), if you are using the HttpCientModule of Angular it is by default.

Sign up to request clarification or add additional context in comments.

3 Comments

unfortunately, it was working very well ,suddenly stop work, Don't know what is the problem??
Can you share the response from the server? does it is a valid JSON? Maybe you broke something in your API endpoint?
do you know ?? it's was just a wrong password for sql server hhhh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.