0
我正在学习ReactJs并希望显示天气数据。该API网址还给:显示来自API的json数据
{
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"conditions": 1
}
}
,"current_observation": {
"image": {
"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
"title":"Weather Underground",
"link":"http://www.wunderground.com"
}, etc. etc.
改成了
componentDidMount() {
$.ajax({
url: "http://api.wunderground.com/api/*****/....",
success: function(data){
this.setState({
wetter: data
});
}.bind(this)
});
}
render() {
return <div>{this.state.wetter.response.termsofService}</div>;
}
But only get console: Uncaught TypeError: Cannot read property 'termsofService' of undefined
我改变了它,它看起来仍然logically..but错误
可否请你更新你已经显示出更清晰的JSON数据? 即'data = {}'带有正确格式化的花括号 –