【发布时间】:2017-05-05 20:44:06
【问题描述】:
我在 react-native 上获取 JSON 数据时遇到问题,here 是我需要的 Json 数据,我编写了以下代码:
function getJsonData(){
return fetch('http://discaricaabusivadibyte.altervista.org/IngBioSched/PROFS.json')
.then((res)=> res.json())
.then((responseJson) => { return responseJson.lista})
.catch(error => console.log(error));
}
var resp=getJsonData();
console.log("faischifo");
console.log(resp.primoanno[0]);
日志:“5173 10207 E ReactNativeJS: undefined is not an object (evalating 'resp.primoanno[0]')”
如果我将 responseJson.lista 包装到 console.log 函数中,我会看到我的 JSON 字符串已格式化。但我不能将它分配给变量。请问你能帮帮我吗? 提前谢谢你
【问题讨论】:
标签: javascript json variables react-native fetch