我想通过将 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/