【发布时间】:2016-04-24 12:00:16
【问题描述】:
我正在学习 ReactJs 并想显示天气数据。 API Url 回馈:
{
"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
我更改了它,它看起来合乎逻辑..但仍然有错误
【问题讨论】:
-
能否请您更新已显示更清晰的 json 数据?即
data = { }带有正确格式的大括号