从获取响应对象中获取文本
我正在使用 fetch
进行 API 调用,一切正常,但在这个特定的实例中,我遇到了一个问题,因为 API 只是返回一个字符串,而不是一个对象.
I'm using fetch
to make API calls and everything works but in this particular instance I'm running into an issue because the API simply returns a string -- not an object.
通常,API 返回一个对象,我可以解析 JSON 对象并获取我想要的内容,但在这种情况下,我无法在响应对象中找到从 API 获取的文本.
Typically, the API returns an object and I can parse the JSON object and get what I want but in this case, I'm having trouble finding the text I'm getting from the API in the response object.
这是响应对象的样子.
我以为我会在正文中找到文本,但我似乎找不到.我在哪里看?
I thought I'd find the text inside the body but I can't seem to find it. Where do I look?
推荐答案
使用 fetch JavaScript API 你可以试试:
Using the fetch JavaScript API you can try:
response.text().then(function (text) {
// do something with the text response
});
还可以查看 fetch 上的文档 >响应 >主体接口方法
Also take a look at the docs on fetch > response > body interface methods
相关文章