从提取响应对象获取文本 [英] Getting Text From Fetch Response Object
问题描述
我正在使用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.
这是响应对象的外观.
Here's what the response object looks like.
我以为可以在体内找到文本,但似乎找不到.我在哪里看?
I thought I'd find the text inside the body but I can't seem to find it. Where do I look?
推荐答案
使用获取JavaScript API,您可以尝试:
Using the fetch JavaScript API you can try:
response.text().then(function (text) {
// do something with the text response
});
还要查看 上的文档获取 响应> 身体界面方法
Also take a look at the docs on fetch > response > body interface methods
这篇关于从提取响应对象获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!