【发布时间】:2021-02-12 14:42:01
【问题描述】:
我正在尝试从此 API 获取 JSON 数据:'https://dog.ceo/api/breeds/list/all' 我什至从官方文档中尝试过几次,但没有任何帮助,我没有收到错误,但屏幕上显示了 nthing
useEffect(() => {
fetch('https://dog.ceo/api/breeds/list/all')
.then((response) => response.json())
.then((json) => setData(json.message))
.catch((error) => console.error(error))
.finally(() => setLoading(false));
}, []);
return (
<View style={{ flex: 1, padding: 24 }}>
{isLoading ? <ActivityIndicator/> : (
<FlatList
data={data}
keyExtractor={({ id }, index) => id}
renderItem={({ item }) => (
<Text>{item.message} ghbdt </Text>
)}
/>
)}
</View>
【问题讨论】:
标签: json reactjs react-native api