【发布时间】:2019-07-03 12:25:42
【问题描述】:
我正在做一个与 react-native 的示例代码非常相似的网络请求。
Networking.js
export default class Networking {
static tryLogin() {
return fetch('https://exampleserver.com')
.then((response) => response.json())
.then((responseJson) => {
return responseJson;
})
.catch((error) => {
console.error(error);
});
}
}
我想检索 responseJson 并在另一个类中处理它,但是,.then((responseJson) 正在返回 objectObject 而不是我的 JSON。我正在使用Networking.tryLogin();调用此方法
当用alert(responseJson) 替换return responseJson 时,它按预期工作,所以它必须与返回有关。
编辑: 在执行 console.log() 时,我得到:
Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
【问题讨论】:
-
只是返回的对象太大,控制台无法显示吗?
-
请说明您是如何使用调用 tryLogin 的
-
您在哪里看到 objectObject 返回?像警报一样?还是您使用 React Native 调试器将其发送到控制台?
-
我正在调用该函数并警告它:
alert(Networking.tryLogin());我在警告框中看到“objectObject”。但是在 console.log() 中是一样的 -
@spender 请看一下编辑。
标签: javascript react-native promise fetch return-value