【问题标题】:I am using ionic and getting an error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>)我正在使用 ionic 并收到错误:SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>)
【发布时间】:2018-07-31 11:29:28
【问题描述】:

这是我的代码:

this.http.get('http://localhost/....)

      .map((res) => res.json())

      .subscribe((

        this.navCtrl.push(OtpPage,{mobileno:this.mobile});

      }, (err) => {
        console.log(err);
      });

并得到以下错误:

SyntaxError: 位置 0 处 JSON 中的意外标记

有人可以帮忙吗??

【问题讨论】:

  • 您从 localhost 上的服务获取的资源不是有效的 JSON。好像是&lt;开头的。
  • 知道如何解决这个@Protectator,谢谢。
  • 是的,请验证您尝试在localhost 上获取的服务是否返回正确的 JSON。

标签: javascript php angularjs ionic-framework


【解决方案1】:

正如@Protectator 所提到的,您来自服务器的响应不是有效的 JSON,当代码尝试调用 res.json() 时会抛出错误。

通过删除/更新以下 sn-p 来尝试。

.map((res))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 2022-01-04
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    • 2019-07-09
    • 1970-01-01
    相关资源
    最近更新 更多