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
这篇关于从获取响应对象中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从获取响应对象中获取文本


基础教程推荐
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01