react-native android fetch json 停止工作

react-native android fetch json stopped working

我在一个 react-native 应用程序上工作了将近一年,我之前写的一个函数突然因为现在的原因停止工作了.. 这是代码片段:

   var array = [];
      fetch('https://reqres.in/api/products/3') //different URL, for testing only
              .then((response) => response.json())
              .then((json) => {  array = json; })
              .then(() => { console.log("get Remote data DONE" + array); 

这段代码在一段时间内运行良好,现在我不得不检查我的代码,它突然不再运行了。我收到“网络请求失败”错误消息。

有什么想法吗?

事实证明,问题不是由我编写的代码或与 react-native 相关的任何其他设置引起的。我尝试了一个不同的模拟设备,这是我为测试这个问题而创建的,并且在这个设备上调试时代码完成没有任何问题。所以我试着简单地擦除我以前使用的虚拟设备(https://github.com/google/android-emulator-m1-preview。现在一切正常。问题解决了!:)