1

我需要将 api 结果作为纯文本检索,我将解析格式错误的 json,但是 response.text() 在这种情况下不起作用:

client.fetch("POST", path, headers, data)
      .then(response => {
        console.log(response.text());});
4

1 回答 1

2

response.text()返回 a Promise,你应该用 another 处理那个 Promise then,像这样:

client.fetch("POST", path, headers, data)
  .then(response => 
       response.text().then(text => console.log(text) );
   );

顺便说一句,如果响应是 JSON 对象,您可以使用response.json()od 代替response.text()

于 2020-07-11T22:09:41.900 回答