Reputation: 5780
I use react-redux to get my API data and put the data into my FlatList
. I know i have to put an array into my FlatList
data
fuction.
But i don't know how to parse my data...
I try const movieData = this.props.movieList[0].movie;
is no working.
How do i parse the data if i want to put the movie
array into my FlatList
?
Any help would be appreciated. Thanks in advance.
Here is my API https://obscure-reaches-65656.herokuapp.com/api?city=Taipei&theater=Centuryasia
Here is my component render
function:
render() {
console.log('render');
console.log(this.props.movieList[0]);
const movieData = this.props.movieList[0];
return (
<View style={{ flex: 1 }}>
<FlatList
data={movieData}
renderItem={this.renderItem}
numColumns={1}
horizontal={false}
keyExtractor={(item, index) => index}
/>
</View>
);
}
Upvotes: 0
Views: 659
Reputation: 5186
Your api response will come in array. And Array is having object. You can assess movie data as below:
let data = response.data;
console.log(JSON.stringify(data));
let movie = data[0]['movie'];
console.log('====================================')
console.log(JSON.stringify(movie));
Here is API call for your url:
const axios = require('axios');
const apiURL = 'https://obscure-reaches-65656.herokuapp.com/api?city=Taipei&theater=Centuryasia';
axios({
method: 'get',
url: apiURL,
headers: {
'Content-Type': 'Application/json',
}
}).then((response) => {
const success = response.status;
let data = response.data;
console.log(JSON.stringify(data));
let movie = data[0]['movie'];
console.log('====================================')
console.log(JSON.stringify(movie));
}).catch((error) => {
alert(error);
});
Upvotes: 1