【发布时间】:2023-01-14 07:44:07
【问题描述】:
我有 Json 数据,想使用 Native Base 读取流派数据,特别是名称键。这是我的 Json,我是从 TMDB API 得到的
流派键使用嵌套数组存储数据
"genres": [
{
"id": 878,
"name": "Science Fiction"
},
{
"id": 12,
"name": "Adventure"
},
{
"id": 28,
"name": "Action"
}
],
我正在尝试像这样从 API 加载数据
fetchDetails = () => {
fetch(
`https://api.themoviedb.org/3/movie/${movie_id}?api_key=9b68fedd9d8cacc97e967403feb9d5fc`
)
.then((response) => response.json())
.then((json) =>
this.setState({
contentGenre: json.genres[0]
})
)
.catch((error) => console.error(error))
.finally(() =>
this.setState({
isCategoriesLoading: false,
})
);
};
我正在尝试像这样显示流派,但没有显示数据
<Text>{contentGenre.name}</Text>
谢谢你的帮助!
【问题讨论】:
-
你能分享你的完整组件吗?
-
你能粘贴你从api响应中得到的整个json吗
标签: json react-native multidimensional-array