2013-12-08 40 views
0

我已经设置了jQuery插件WhatWeather及其工作正常,但有一点问题。从jQuery获取描述whatweather

当我得到天气数据时,我得到这个txt文件。

{ "data": { "current_condition": [ {"cloudcover": "100", "humidity": "100", "localObsDateTime": "2013-12-08 02:23 PM", "observation_time": "01:23 PM", "precipMM": "4.3", "pressure": "1008", "temp_C": "7", "temp_F": "45", "visibility": "7", "weatherCode": "296", "weatherDesc": [ {"value": "Light rain" } .....] }} 

为了让我的网页上公布的数据显示,我使用“currentCondition.cloudcover”,然后我得到的cloudcover 100,但我不能让天气的描述我都试过“currentCondition.weatherDesc”,然后我得到输出“Object:Object”。而不是“小雨”如何从txt文件中获得“Light Rain”值?

回答

2

wheatherDesc本身也是一个对象的数组所以尽量currentCondition.weatherDesc[0].value

所以,总体来说:

data.current_condition[0].weatherDesc[0].value