React Nativeで問題が発生していますが、これはReact Nativeで問題が発生しています。すべての "キー"。笑「オブジェクトではない値の要求されたキー」JSONとReact Native
まず、これは私のJSONの構造である:
{ "Spot[]": [
{"id":1,"name": "Relais Villenus"},
{"id":2, "name": "Random"}
]}
私がこれまでJSONの多くで動作するように取得していないが、彼らはこのようなことはありませんでしたし、それは私を失いました!
私のクラスには、データを要求:
dataSource: ds.cloneWithRows(responseJson),
:
class ListScreen extends Component{
static navigationOptions = {
tabBarLabel: 'Liste',
};
constructor(props) {
super(props);
this.state = {
isLoading: true
}
}
componentDidMount() {
return fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseJson) => {
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.setState({
isLoading: false,
dataSource: ds.cloneWithRows(responseJson.Spot),
});
})
.catch((error) => {
console.error(error);
});
}
render() {
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
return (
<View style={{flex: 1, paddingTop: 20}}>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) => <Text>{rowData.name}</Text>}
/>
</View>
);
}
}
は私が
dataSource: ds.cloneWithRows(responseJson.Spot[]),
ようまたはこのようGitHubの私がここで何を読んでかに基づいて異なるものを試してみました
と表示されます。
renderRow={(rowData) => <Text>{rowData.Spot.name}</Text>}
または
renderRow={(rowData) => <Text>{rowData.Spot[name]}</Text>}
私のコードは、このJSONで動作します。私は私が正しくデータをフェッチする方法がわからないため、エラーがあると仮定し、なぜhttps://facebook.github.io/react-native/movies.json
これがあります。
ありがとうございます!
このds.cloneWithRowsを試してください(responseJson ['Spot []']) ' –
ああ、ありがとうございますハッサン! :) できます !私はresponseJsonを試しました。['Spot []'])。ポイント:FML!再度、感謝します ! – YoungDreamer