0
当我在React Native应用程序中收到我的JSON时遇到问题。React原生网络JSON响应
我做一个简单的读取请求得到它
getApplicationList()
{
return fetch('http://192.168.X.X/index.php')
.then((response) => response.json())
.then((responseJson) => {
return responseJson;
})
.catch((error) => {
return 'There has been a problem with your fetch operation: ' + error.message;
});
}
,但是当我在渲染功能做出console.error(getApplicationsList());
,我在Android模拟器得到一个非常奇怪的日志:
console.error: {"_40":"0","_65":"0","_55":"null","_72":"null"}
在我的PHP文件中,我返回了一个JSON编码的响应,当我在导航器中输入我的URL(使用'localhost')时,我可以得到它。
当我从模拟器启动应用程序时,我用我的计算机IP更改localhost地址,当我在浏览器中输入此URL时,我得到一个Cannot GET /index.php
响应。我不知道这是否正常,我在这一切之间感觉有点失落。
非常感谢您的帮助
这是因为'fetch'返回一个承诺。把console.error放在第二个.then()函数中,并调用渲染'this.getApplicationList()'中的方法' – Raymond
我在第二个.then()中放置了一个console.error,但是没有任何东西显示在模拟器上。看来它不会通过... – Koko
尝试控制台记录您的响应和/或'response.json()' – MattyK14