我是这样工作的
这是按钮
<Button onPress={this._onPressButton} accessibilityLabel="tap!!!" />
这是行动
_onPressButton() {
return fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson.movies);
})
.catch((error) => {
console.error(error);
});
}
结果
[14:30:19] Array [
[14:30:19] Object {
[14:30:19] "id": "1",
[14:30:19] "releaseYear": "1977",
[14:30:19] "title": "Star Wars",
[14:30:19] },
[14:30:19] Object {
[14:30:19] "id": "2",
[14:30:19] "releaseYear": "1985",
[14:30:19] "title": "Back to the Future",
[14:30:19] },
[14:30:19] Object {
[14:30:19] "id": "3",
[14:30:19] "releaseYear": "1999",
[14:30:19] "title": "The Matrix",
[14:30:19] },
[14:30:19] Object {
[14:30:19] "id": "4",
[14:30:19] "releaseYear": "2010",
[14:30:19] "title": "Inception",
[14:30:19] },
[14:30:19] Object {
[14:30:19] "id": "5",
[14:30:19] "releaseYear": "2014",
[14:30:19] "title": "Interstellar",
[14:30:19] },
[14:30:19] ]
[14:30:19] Array [
[14:30:19] Object {
[14:30:19] "id": "1",
[14:30:19] "releaseYear": "1977",
[14:30:19] "title": "Star Wars",
[14:30:19] },
[14:30:19] Object {
[14:30:19] "id": "2",
[14:30:19] "releaseYear": "1985",
[14:30:19] "title": "Back to the Future",
[14:30:19] },
[14:30:19] Object {
[14:30:19] "id": "3",
[14:30:19] "releaseYear": "1999",
[14:30:19] "title": "The Matrix",
[14:30:19] },
[14:30:19] Object {
[14:30:19] "id": "4",
[14:30:19] "releaseYear": "2010",
[14:30:19] "title": "Inception",
[14:30:19] },
[14:30:19] Object {
[14:30:19] "id": "5",
[14:30:19] "releaseYear": "2014",
[14:30:19] "title": "Interstellar",
[14:30:19] },
[14:30:19] ]