【发布时间】:2020-09-03 02:16:00
【问题描述】:
我正在使用 Axios(Apisauce) 将 API 连接到 React Native App; 这是我尝试使用 FlatList 在应用内显示的 JSON 文件:
{
"data": {
"sideMenu": {
"url": "https://google.com",
"icons": [
{
"id": 1,
"url": "https://google.com",
"status": 1
},
]
},
}
}
当我尝试将其登录到控制台时,使用 console.log(response.data) 会返回所有 API 信息,但使用 console.log(response.data.data) 不会返回我正在寻找的对象!
我尝试过JSON.stringify() 或toString(),但它们似乎都不起作用。
我的 Axios 代码:
const getServices = () => {
const service = "https://api.team-grp.ir/app/json/services2.json/";
return client.get(service);
};
我的源代码:
const ServiceInfo = async () => {
await getServices()
.then((response) => {
if (response.ok) {
setServicesData(response.data.data);
}
})
.catch((error) => {
console.warn(error);
setServicesData([]);
});
};
useEffect(() => {
ServiceInfo();
});
【问题讨论】:
-
你能分享你的 axios 代码吗?
-
请附上您的源代码。
-
@DevLover 编辑的主要问题
-
@C.K 编辑主要问题
标签: react-native axios react-native-flatlist apisauce