- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试解析 json 中的响应正文以便将其保存在某个状态时,我从标题中收到错误。由于某种原因,response.json 未定义。这是我的回复:
16:28:30: Response {
16:28:30: "_bodyInit": "\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6ImFkbWluIiwibmJmIjoxNTE1MjQ4OTEwLCJleHAiOjE1MTUyNTAxMTAsImlhdCI6MTUxNTI0ODkxMH0.8zIX0PjC0XHBiHTtXlDvNxbOADj2NgtxK8zC-MqxoCg\"",
16:28:30: "_bodyText": "\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6ImFkbWluIiwibmJmIjoxNTE1MjQ4OTEwLCJleHAiOjE1MTUyNTAxMTAsImlhdCI6MTUxNTI0ODkxMH0.8zIX0PjC0XHBiHTtXlDvNxbOADj2NgtxK8zC-MqxoCg\"",
16:28:30: "headers": Headers {
16:28:30: "map": Object {
16:28:30: "access-control-allow-credentials": Array [
16:28:30: "true",
16:28:30: ],
16:28:30: "cache-control": Array [
16:28:30: "public, max-age=0",
16:28:30: ],
16:28:30: "content-length": Array [
16:28:30: "182",
16:28:30: ],
16:28:30: "content-type": Array [
16:28:30: "application/json; charset=utf-8",
16:28:30: ],
16:28:30: "date": Array [
16:28:30: "Sat, 06 Jan 2018 14:28:30 GMT",
16:28:30: ],
16:28:30: "expires": Array [
16:28:30: "-1",
16:28:30: ],
16:28:30: "server": Array [
16:28:30: "Microsoft-IIS/10.0",
16:28:30: ],
16:28:30: "x-aspnet-version": Array [
16:28:30: "4.0.30319",
16:28:30: ],
16:28:30: "x-powered-by": Array [
16:28:30: "ASP.NET",
16:28:30: ],
16:28:30: },
16:28:30: },
16:28:30: "ok": true,
16:28:30: "status": 200,
16:28:30: "statusText": undefined,
16:28:30: "type": "default",
16:28:30: "url": "url",
16:28:30: }
这是我收到错误的代码:
export function loginAction(data) {
return dispatch => Promise.all([
dispatch(loginStarted()),
loginService(data).then(response => {
console.log(response);
if (!response.ok) {
Alert.alert('ERROR', 'User or password is incorrect');
dispatch(loginFailed('User or password is incorrect'));
}
else {
Alert.alert('OK', 'Login is a success');
}
}).then((response) => response.json()).then((response) => {
console.log(response);
dispatch(loginSuccess(response));
})
]);
}
在 (response) => response.json() 所在的行收到错误。
这是获取请求:
export const loginService = (user) => {
return fetch(`${httpApiUrl}/api/userdata/ReactVerify`, {
method: 'POST',
headers: {
'Accept': '*/*',
'Content-Type': 'application/json',
},
body: JSON.stringify(user)
})
.then(function (response) {
return response;
});
};
我也试过 response.text() 而不是 json(),但它仍然是未定义的。我如何从 _bodyInit 获取文本,或者我做错了什么?谢谢。
最佳答案
呃,为什么要使用两个 .then
调用?前一个回调不返回任何内容,因此链式 promise 以 undefined
解析,而这正是后一个回调接收的内容。只使用一个 - 当状态不正常时也不要调用 response.json()
。
loginService(data).then(response => {
console.log(response);
if (!response.ok) {
Alert.alert('ERROR', 'User or password is incorrect');
dispatch(loginFailed('User or password is incorrect'));
} else {
Alert.alert('OK', 'Login is a success');
return response.json().then(data => {
console.log(data);
dispatch(loginSuccess(data));
});
}
})
关于javascript - react native : Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'response.json' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48128543/
我正在使用 Test Cafe 中使用 Resemble.JS 库的函数来比较实际屏幕截图和基本屏幕截图。在我的夹具中,我有两个测试,由于屏幕截图不匹配,两个测试都应该在报告中失败,但唯一的第一个测试
这个问题在这里已经有了答案: What does IndexOutofRangeException mean? (3 个答案) 关闭 9 年前。 string Query = "SELECT [AA
错误日志: System.TypeInitializationException was unhandled Message="The type initializer for 'MaxDavid
使用 Python 2.7 和 Django 1.10.4,我尝试将我的应用程序部署到 pythonanywhere,但我不断收到此错误。 错误日志 wsgi.py import os import
我有一个名为 Form1 的表单: 有一个 ComboBox 和一个 TextBox,当我从 ComboBox 中选择 US$ 时,它必须从数据库中检索数据并显示TextBox 中的 150。 这是我
我正在尝试制作 slider 益智游戏,但在我的 form1 中调用 myBoard.paint(e.Graphics) 时,我不断收到错误“NullReferenceException 未处理”。请
我目前正在开发一个数据库,用于跟踪停在 parking 场的车辆。但是,我在将新记录保存到数据库表时遇到了一些问题。现在我对编程还很陌生,所以我无法理解我收到的错误。我试过查找它并发现了类似的情况,但
我编写了一个 Android 应用程序 (4.4.2),它在大多数时间都能正确连接/断开 BLE 外围设备。但是,每隔一段时间我就会在 Bluetootgatt.java onClientConnec
当我尝试运行 Facebook C# SDK 附带的 WP7 示例应用程序时,我收到此异常: File or assembly name 'Microsoft.Contracts, Version=1
我正在尝试学习如何在 Scala 中使用 Try with 进行理解。 在下面的示例代码中( result1 ), 如果 for comprehension 中的最后一条语句抛出未处理的异常, 代码不
我遇到了一个小问题,在调试了所有应用程序后,我注意到这是导致问题的文件,并向我返回了 UnhandledPromiseRejection 'use strict' const connection =
我对 Java(特别是 Android)相当陌生。我试图让用户从图库中选择图像,然后应用程序会将图像从图库复制到应用程序目录中的文件夹(以及显示他们在图像按钮中选择的图片)。但是,我收到“未处理的异常
我已从 iOS SDK 4.2 升级到 iOS SDK 5.0。当我现在尝试编译当前项目时,出现以下错误。 关于这里出了什么问题的任何想法?我已经阅读了所有我能找到的“mtouch failed wi
由于我正在考虑使用 WCF,所以我认为最好只是按照一个简单的教程来尝试一下。 3 小时后,我只有一个异常(exception)要显示。它不会消失。 我排除了没有加载 app.config 的可能性。如
我正在尝试在带有 .net 4.5 的 VS 2012 中使用带有 Telerik OpenAccess 的 WCF Plain 服务。 我尝试了 telerik 开发人员手册并创建了服务和客户端。
我遇到了这个错误 Program.exe 中 0x0049b946 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000090。 错误指向这一行: // thread
对于我的 Monodroid 应用程序,我想在出现未处理的异常后执行以下操作: 将错误发送到服务器。 通知用户应用程序已崩溃(可能使用 toast 消息)。 优雅地退出应用程序。 我已经实现了#1,但
我使用 JQuery 的表排序器对表进行排序,但我遇到了空表抛出异常的问题。所以我在脚本中添加了一个条件,但现在问题出在条件上。 : $(document).ready(function ($) {
我的构造函数的目标是: 打开一个文件读入特定字符串(“%%%%%”)之间存在的所有内容将每个读取行放在一个变量(历史记录)中将最终变量添加到 char 类型的双指针 (_stories)关闭文件。 但
我正在使用 Visual Studio 2005 和 IIS 6.0.. 我在事件日志中有这个警告。我试图找到它是什么。我工作时从未经历过这个异常(exception)。可以做什么,在哪里可以做,不再
我是一名优秀的程序员,十分优秀!