显示API中的json数据

时间:2016-04-24 12:00:17

标签: json reactjs

我正在学习ReactJs并希望显示天气数据。 API网址返回:

withTrashed()

将其更改为

{
  "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.

我改变了它,它看起来很逻辑......但仍然是错误

1 个答案:

答案 0 :(得分:0)

不要将wetter设置为data.response,只需将其设为data

这样您就可以到达整个对象。 E.g:

return <div>{this.state.wetter.response.termsofService}</div>;
    // http://www.wunderground.com/weather/api/d/terms.html

return <div>{this.state.wetter.response.features.conditions}</div>;
    // 1

return <div>{this.state.wetter.current_observation.image.url}</div>;
    // http://icons.wxug.com/graphics/wu2/logo_130x80.png