json - 语法错误 : Unexpected token e in JSON at position 1 at JSON. 解析(<匿名>)

标签 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: Unexpected token h in JSON at position 0 at JSON.parse () at XMLHttpRequest.onLoad (http://localhost:4000/vendor.js:33488:51) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4000/polyfills.js:8108:31) at Object.onInvokeTask (http://localhost:4000/vendor.js:78969:33) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4000/polyfills.js:8107:60) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4000/polyfills.js:7880:47) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4000/polyfills.js:8183:34) at invokeTask (http://localhost:4000/polyfills.js:9429:14) at XMLHttpRequest.globalZoneAwareCallback (http://localhost:4000/polyfills.js:9466:21)

最佳答案

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

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

关于json - 语法错误 : Unexpected token e in JSON at position 1 at JSON. 解析(<匿名>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58072330/

相关文章:

json - 使用逻辑应用修改 JSON 数据

angularjs - 从服务获取异步数据

javascript - 遍历包含数组的 JSON 对象包含包含数组的对象包含等

php - 修复 MySQL/PHP 中的 JSON 格式

css - 如何使用 css 和 angular7 动态显示文本省略号?

javascript - 如何在 angular2 中使用 RxJS?

angular - 如何在 this.formgroup.value() 上获取 Number 类型的值?

javascript - Angular 5 : Can't Resolve All Parameters for e: (? )

python - 使用生成器逐行读取 json