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.
这是响应对象的样子.
我以为我会在正文中找到文本,但我似乎找不到.我在哪里看?
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
这篇关于从获取响应对象中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从获取响应对象中获取文本


基础教程推荐
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01