目标:在 Angular 中检索单个值“test”。
问题:我收到错误消息
Error: SyntaxError: Unexpected token e in JSON at position 1 at JSON.parse ()
我缺少什么语法?
ASP.NET
// https://localhost:44353/api/Jobadvertisement/VVValidate/4
[HttpGet("VVValidate/{id:int}")]
public ActionResult<String> VVValidate(int id)
{
return "test";
}
Angular
const url = environment.url
let asdfasdf2 = url + 'api/Jobadvertisement/VVValidate/' + "4";
var dsfsdssf = this.http.get(asdfasdf2).subscribe(data => {
console.log(data);
});
最佳答案
你能尝试在 Angular 中使用 httpOptions 吗:
const url = environment.url;
let asdfasdf2 = url + 'api/Jobadvertisement/VVValidate/' + "4";
var dsfsdssf = this.http.get(asdfasdf2, { responseType: 'text' }).subscribe(data => { console.log(data); });
关于asp.net - 使用 Angular 从 webapi 检索单个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56824740/