我有一个链接可以从我的Google Spreadsheet中生成JSON数据,我只是想将这些数据显示到我的“平面视图”组件中,但是我不知道为什么它没有在“我的平面列表”中显示任何数据
这是我从电子表格中获取的JSON数据
{"Arbaz":[{"id":1,"name":"Arbaz","roll":12},{"id":2,"name":"Imtiyaz","roll":34},{"id":3,"name":"John","roll":45},{"id":3,"name":"James","roll":23}]}
这是我的React Native代码:
export default class App extends React.Component {
state = {
data: []
};
componentWillMount() {
this.fetchData();
}
fetchData = async () => {
//const response = await fetch("https://randomuser.me/api?results=10");
const response = await fetch("MYLINK");
const json = await response.json();
this.setState({ data: json.results });
};
render() {
return (
<View style={styles.container}>
<Text>Nothing to show</Text>
<FlatList
data={this.state.data}
keyExtractor={(x, i) => i}
renderItem={({ item }) =>
<Text>
{`${item.data.Arbaz.id} ${item.data.Arbaz.id}`}
</Text>}
/>
</View>
);
}
}