【发布时间】:2020-03-20 14:25:30
【问题描述】:
我是 reactjs 的新手: 我有一个带有一项服务的 springboot,它返回一个像这样的 ResponseEntity:
@RequestMapping(value = "/startTest")
public ResponseEntity<String> runTest {
String response;
if (this.values>0){
response=String.format("Test Failed: %s", summary.getFailures().get(0).getException().getMessage());
}
else{
response="Test Successfull!";
}
return ResponseEntity.status(HttpStatus.OK).body(response);
在反应中,我有这个读取正文的功能:
var url = "http://127.22.22.12:8090/startTest";
await fetch(url)
.then(function(response){return response.json();})
.then(function(data){const items=data;
console.log(items)
})
但是我在控制台中有这个错误:
Uncaught (in promise) SyntaxError: Unexpected token T in JSON at position 0
如果写 console.log(response.text()) 我查看 Promise OBJECT 但如何将 PROMISE VALUE 作为文本获取?
谢谢 问候
【问题讨论】:
标签: javascript java reactjs spring-boot