0

我想显示天气预报。到目前为止,我只设法展示了一天。

HTML & Jquery 代码: http: //pastebin.com/cpZ0pE7G

json 以这种格式显示。

{
   "cod":"200",
   "message":0.0152,
   "city":{
      "id":524901,
      "name":"Moscow",
      "coord":{
         "lon":37.615555,
         "lat":55.75222
      },
      "country":"RU",
      "population":1000000
   },
   "cnt":4,
   "list":[
      {
         "dt":1375866000,
         "temp":{
            "day":26.19,
            "min":21.82,
            "max":26.19,
            "night":21.82,
            "eve":25.22,
            "morn":26.19
         },
         "pressure":1010.53,
         "humidity":77,
         "weather":[
            {
               "id":801,
               "main":"Clouds",
               "description":"few clouds",
               "icon":"02d"
            }
         ],
         "speed":1.6,
         "deg":4,
         "clouds":24
      },
      {
         "dt":1375952400,
         "temp":{
            "day":24.92,
            "min":17.73,
            "max":25.32,
            "night":17.73,
            "eve":24.71,
            "morn":17.75
         },
         "pressure":1013.91,
         "humidity":71,
         "weather":[
            {
               "id":800,
               "main":"Clear",
               "description":"sky is clear",
               "icon":"01d"
            }
         ],
         "speed":1.61,
         "deg":20,
         "clouds":0
      },
      {
         "dt":1376038800,
         "temp":{
            "day":25.87,
            "min":16.74,
            "max":26.65,
            "night":22.17,
            "eve":26.42,
            "morn":16.74
         },
         "pressure":1011.31,
         "humidity":71,
         "weather":[
            {
               "id":800,
               "main":"Clear",
               "description":"sky is clear",
               "icon":"01d"
            }
         ],
         "speed":1.66,
         "deg":252,
         "clouds":0
      },
      {
         "dt":1376125200,
         "temp":{
            "day":22.72,
            "min":19.68,
            "max":25.42,
            "night":19.68,
            "eve":24.82,
            "morn":21.02
         },
         "pressure":1007.87,
         "humidity":73,
         "weather":[
            {
               "id":502,
               "main":"Rain",
               "description":"heavy intensity rain",
               "icon":"10d"
            }
         ],
         "speed":2.11,
         "deg":278,
         "clouds":80,
         "rain":15
      }
   ]
}

我只能解析第一行。我如何解析其他行?

4

1 回答 1

0

当你看到括号时,它是一个数组,所以你必须通过数组键找到变量。weather.list[0].temp.day将返回您 26.19。weather.list[0].weather[0].main将返回您“云”weather.list[1].weather[0].main并将返回您“清除”。

于 2016-04-29T21:04:58.557 回答