android - React-Native 通过教程 Facebook 获取 JSON 返回错误

标签 android ios json facebook react-native

通过教程 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/

相关文章:

Android 应用程序图标尺寸太小

Android - 如何直接将推文发布到 Twitter(没有隐式 Intent 或其他应用程序)?

android - 我如何使用 google places 在 android 中查找位置

ios - 有什么方法可以强制 UILocalNotification 默认为警报?

java - 将列表序列化为 json 时出现异常

php - 这需要如何解析 JSON?

android - 我的应用程序没有出现在模拟器中

iphone - 加载 View 后隐藏状态栏留下黑条

ios - 将 Swift 文件导入 Obj-C 文件

json - 解析 JSON 数组