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 = {}'帶有正確格式化的花括號 –