通过教程 Facebook 返回错误的 React-Native 获取 JSON
错误为 null is not an object (evaluating 'this.state.datasource')
我该如何处理我的代码
class ModuleRecView extends Component {
componentWillMount() {
return fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.setState({
isLoading: false,
dataSource: ds.cloneWithRows(responseJson.movies),
}, function() {
// do something with new state
});
})
.catch((error) => {
console.error(error);
});
}
render() {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) => <Text>{rowData.title}, {rowData.releaseYear}</Text>}
/>
</View>
);
}
}
export default ModuleRecView;
最佳答案
我认为问题出在这个链接 https://facebook.github.io/react-native/movies.json它返回 404 页面未找到。您可以尝试使用另一个 json 链接或在此处找到您需要的数据 https://github.com/facebook/react-native/blob/master/website/src/react-native/movies.json
关于android - React-Native 通过教程 Facebook 获取 JSON 返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44505245/