react-native - 反应本机传奇获取数据格式问题
问题描述
我正在使用 redux-saga 从我的 React Native 应用程序中的简单 json-server 获取数据。看起来获取成功,但我无法在返回的响应对象中提取我正在寻找的数据。以下是我的生成器函数中的代码:
function* loadOpenItemsSaga(action) {
try {
const response = yield call(fetch, baseUrl + 'thingsList', { method: 'GET'});
console.log('loadOpenItemsSaga successful', response);
yield put({ type: ActionTypes.ACTION_SUCCESS, resp: response });
} catch (error) {
const errorMessage = { code: error.code, message: error.message };
console.log('loadOpenItemsSaga fail', errorMessage);
yield put({ type: ActionTypes.ACTION_FAILURE, error: errorMessage });
}
}
控制台日志打印为:
10:55:59: loadOpenItemsSaga successful Response {
10:55:59: "_bodyBlob": Blob {
10:55:59: "_data": Object {
10:55:59: "blobId": "eb3d53ce-ecc8-4e48-9f53-1c9b4129d300",
10:55:59: "offset": 0,
10:55:59: "size": 1429,
10:55:59: },
10:55:59: },
10:55:59: "_bodyInit": Blob {
10:55:59: "_data": Object {
10:55:59: "blobId": "eb3d53ce-ecc8-4e48-9f53-1c9b4129d300",
10:55:59: "offset": 0,
10:55:59: "size": 1429,
10:55:59: },
10:55:59: },
10:55:59: "headers": Headers {
10:55:59: "map": Object {
10:55:59: "access-control-allow-credentials": Array [
10:55:59: "true",
10:55:59: ],
10:55:59: "cache-control": Array [
10:55:59: "public, max-age=0",
10:55:59: ],
10:55:59: "connection": Array [
10:55:59: "keep-alive",
10:55:59: ],
10:55:59: "content-type": Array [
10:55:59: "application/json; charset=utf-8",
10:55:59: ],
10:55:59: "date": Array [
10:55:59: "Mon, 20 Aug 2018 05:25:59 GMT",
10:55:59: ],
10:55:59: "etag": Array [
10:55:59: "W/\"595-QGa7N/U2dPsbWUU83//t6RMzYwQ\"",
10:55:59: ],
10:55:59: "expires": Array [
10:55:59: "-1",
10:55:59: ],
10:55:59: "transfer-encoding": Array [
10:55:59: "chunked",
10:55:59: ],
10:55:59: "vary": Array [
10:55:59: "Origin",
10:55:59: ],
10:55:59: "x-content-type-options": Array [
10:55:59: "nosniff",
10:55:59: ],
10:55:59: "x-powered-by": Array [
10:55:59: "Express",
10:55:59: ],
10:55:59: },
10:55:59: },
10:55:59: "ok": true,
10:55:59: "status": 200,
10:55:59: "statusText": undefined,
10:55:59: "type": "default",
10:55:59: "url": "http://localhost:3001/thingsList",
10:55:59: }
我期待的实际内容是:
{
"thingsList": [
{
"id": 0,
"name":"Orange",
"from": "Jill",
"fromImage": "images/IMG_9352.jpg",
"createDate": "2018-8-817:57:28.556094Z",
"needBy": "Today",
"description":"to put for kids box tomo, bring from down stores",
"status": "open",
"statusUpdatedOn": "2018-8-8T17:57:28.556094Z",
"statusUpdatedBy": "Jack",
"assignedTo": "Jack"
},
{
"id": 1,
"name":"Cryons",
"from": "Jill",
"fromImage": "images/IMG_9352.jpg",
"createDate": "2018-8-8T17:57:28.556094Z",
"needBy": "In a week",
"description":"bring from opp bangle store",
"status": "open",
"statusUpdatedOn": "",
"statusUpdatedBy": "Jack",
"assignedTo": "Jack"
},
{
"id": 2,
"name":"Eggs",
"from": "Jill",
"fromImage": "images/IMG_9352.jpg",
"createDate": "2018-9-8T17:57:28.556094Z",
"needBy": "Today",
"description": "some 10 eggs",
"status": "open",
"statusUpdatedOn": "2018-8-10T17:57:28.556094Z",
"statusUpdatedBy": "Jack",
"assignedTo": "Jack"
},
{
"id": 3,
"name": "KG sheet",
"from": "Jill",
"createDate": "2018-8-6T17:57:28.556094Z",
"fromImage": "images/IMG_9352.jpg",
"needBy": "Today",
"description":"black n white, 1 each",
"status": "open",
"statusUpdatedOn": "2018-8-9=T17:57:28.556094Z",
"statusUpdatedBy": "Jack",
"assignedTo": "Jack"
}
]
}
如何从 Response 对象中提取数据?response.json() 不工作
问候, 拉什米
解决方案
推荐阅读
- java - 使用流检查映射中的键并且值不为空
- c++ - 我们可以像rabbitmq订阅客户端那样将JMS发布者与AMQP订阅者一起使用吗?
- php - 追加/添加一个单击行按钮时在表格行内标记jquery / php
- r - 串联使用 ggplot 和 alleffects
- postgresql - repmgr - 从失败的主服务器中恢复?
- python - Django:ORM 设计问题
- python - 将复杂/扁平化的 JSON 转换为 DataFrame
- c# - 如何将占位符或 0 添加到 Blazor 日期
- node.js - 如何在 Firebase 云函数中进行 API 调用?
- java - 关闭 JFrame 后清空 ArrayList