【发布时间】:2020-04-10 17:22:18
【问题描述】:
我是一名初学者程序员,我决定制作我的第一个项目 - 天气应用程序。虽然我有问题,但我无法将解析的信息显示在屏幕上,但如果我使用 console.log,信息会显示在控制台中。
我在现场做所有这些:https://snack.expo.io/
Copying you the codes and comment inside it console.logs
**CODE**
import React, { Component, createElement } from 'react';
import {
StyleSheet,
Text,
View,
Image,
ImageBackground,
ActivityIndicator,
} from 'react-native';
class App extends Component {
constructor(props) {
super(props);
this.state = {
todos: [],
isLoading: true,
};
}
componentDidMount = async () => {
fetch(
'API'
)
.then(res => res.json())
.then(data => {
this.setState({ todos: data });
})
.catch(error => console.error(error))
.finally(() => {
this.setState({ isLoading: false });
});
};
render() {
const { data, isLoading } = this.state;
return (
<View>
<Text>
{data.sys.id}
</Text>
</View>
);
}
}
export default App;
谢谢!
【问题讨论】:
标签: json react-native parsing weather-api