为什么这会引发错误?
deleteUser(userId: string) {
this.dataService.deleteUser(userId).subscribe((response: string) => {
console.log(response);
});
}
“语法错误:JSON 中位置 1 处出现意外标记 f
在 JSON.parse()
在 XMLHttpRequest.onLoad (https://localhost:5001/vendor.js:34968:51)
在 ZoneDelegate.invokeTask (https://localhost:5001/polyfills.js:412:35)
在 Object.onInvokeTask (https://localhost:5001/vendor.js:72879:33)
在 ZoneDelegate.invokeTask (https://localhost:5001/polyfills.js:411:40)
在 Zone.runTask (https://localhost:5001/polyfills.js:180:51)
在 ZoneTask.invokeTask [作为调用] (https://localhost:5001/polyfills.js:493:38)
在 invokeTask (https://localhost:5001/polyfills.js:1634:18)
在 XMLHttpRequest.globalZoneAwareCallback (https://localhost:5001/polyfills.js:1671:25)”
响应是纯字符串值,状态为 200。
我错过了什么?
使用正确的响应类型(默认为 JSON)更新 dataService 中的 deleteUser 方法。另外,我假设这就是您使用 httpClient 的地方。
httpClient.get('your_endpoint', { responseType: 'text' }).subscribe(result => {
console.log(result);
});
您返回的是文本,而不是 JSON。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)