如果您有无效的JSON从服务器返回到前端。有没有办法在Angular中自动更正它?还是服务器作业可以正确发送?
data: "{\"fiillingingo\": {\"refere\": null, \"secondary\": [], \"references\": [{\"referenc...}"
尝试JSON.parse()后发生错误
core.js:15723 ERROR SyntaxError: Unexpected token u in JSON at position 639`
出于某种原因,当我从后端响应中复制并粘贴并将其手动设置为变量时,就很好了,但是当我直接从http调用中设置变量时,就是得到错误
Sercice.ts
export interface Response{
x: string;
y: number;
}
@Injectable({
providedIn: 'root'
})
export class DraftService {
constructor(private http: HttpClient) { }
getDraftData(ID: number):Observable<Response>{
var url = `/services/****/drafts/${ID}/lob`;
return this.http.get<Response>(url);
}
}
componnent.ts
constructor(public data: DraftDocumentService) { }
ngOnInit() {}
loadClob(){
this.data.getDraftData(this.ID).subscribe(response => {
this.formatJSON =response.x;
console.log(typeof this.formatJSON);
},
error =>{
console.log('error');
});
}