【问题标题】:ERROR SyntaxError: Unexpected end of JSON input?错误语法错误:JSON 输入意外结束?
【发布时间】:2018-06-13 23:49:28
【问题描述】:

我有一个角度项目,但出现以下错误:

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)

在 chrome 控制台中。 (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);
      });
  }

第57行是

var jsonObject = data.json();

谁能帮帮我..

【问题讨论】:

    标签: angular


    【解决方案1】:
    1. 您将 observable 命名为 promise,这非常令人困惑。

    2. 我猜你不需要data.json(),如果你使用的是Angular的HttpCientModule,它是默认的。

    【讨论】:

    • 很遗憾,一直很好用,突然停止工作,不知道是什么问题??
    • 你能分享服务器的响应吗?它是有效的 JSON 吗?也许您破坏了 API 端点中的某些内容?
    • 你知道吗??这只是 sql server 的密码错误hhhh。
    猜你喜欢
    • 2014-01-16
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    相关资源
    最近更新 更多