语法错误:JSON.parse 位置 1 处的 JSON 中的意外标记 e(<匿名>)

use*_*126 4 json angular-services angular

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

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

组件文件

respondDashboardLink: string;
this.refService.getRespondDashboardUrl().subscribe(result => {
  this.respondDashboardLink = result;
});
Run Code Online (Sandbox Code Playgroud)

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

我得到的错误

SyntaxError: JSON.parse () at 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 ) 在 ZoneDelegate 的 Object.onInvokeTask ( http://localhost:4000/vendor.js:78969:33 )。 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 [as invoke ] (http://localhost:4000/polyfills.js:8183:34 ) 在 invokeTask ( http://localhost:4000/polyfills.js:9429:14 ) 在 XMLHttpRequest.globalZoneAwareCallback ( http://localhost:4000/polyfills. js:9466:21 )

Hsu*_*Lee 15

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

this.http.get(`ref/RespondDashboardUrl`, {responseType: 'text'})
Run Code Online (Sandbox Code Playgroud)