我正在从url中获取json数据,使用以下内容:
this.http.get('http://localhost:3200/mydata').subscribe(data => {
console.log(data);
});我的意思是返回json,所以一切正常。
但是现在我也有了一个返回html的url。
我试着:
this.http.get('http://localhost:3200/nonjson').subscribe(data => {
console.log(data);
});我收到以下错误消息:
Http failure during parsing ... 我怎么才能解决这个问题?
发布于 2019-01-24 13:08:53
然后应该指定响应类型(因为JSON 是默认请求类型,所以存在解析错误):
this.http.get('http://localhost:3200/nonjson', {responseType: 'text'}).subscribe(data => {
console.log(data);
});https://stackoverflow.com/questions/54347377
复制相似问题