SyntaxError:JSON.parse(<anonymous>)上位置1处的JSON中意外的令牌e

时间:2019-09-24 02:35:14

标签: json angular angular-services

我想通过将API调用到Angular中来获取字符串值。 这是我在做什么 服务文件-

 public getRespondDashboardUrl(): Observable<any> {
    return this.http.get(`ref/RespondDashboardUrl`);
  }

组件文件

respondDashboardLink: string;
this.refService.getRespondDashboardUrl().subscribe(result => {
  this.respondDashboardLink = result;
});

功能返回URL作为字符串值https://abcd.xyz.com/Respond/App/index.html#ActionCenter/0

我得到的错误

  

SyntaxError:JSON中位置0处的意外令牌h       在JSON.parse()       在XMLHttpRequest.onLoad(http://localhost:4000/vendor.js:33488:51)       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask(http://localhost:4000/polyfills.js:8108:31)       在Object.onInvokeTask(http://localhost:4000/vendor.js:78969:33)       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask(http://localhost:4000/polyfills.js:8107:60)       在Zone.push ../ node_modules / zone.js / dist / zone.js.Zone.runTask(http://localhost:4000/polyfills.js:7880:47)       在ZoneTask.push ../ node_modules / zone.js / dist / zone.js.ZoneTask.invokeTask上[作为调用](http://localhost:4000/polyfills.js:8183:34)       在invokeTask(http://localhost:4000/polyfills.js:9429:14)       在XMLHttpRequest.globalZoneAwareCallback(http://localhost:4000/polyfills.js:9466:21

1 个答案:

答案 0 :(得分:2)

如果响应类型是字符串。更多类型检查responseType

this.http.get(`ref/RespondDashboardUrl`, {responseType: 'text'})