我已经设置了 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”,然后得到云覆盖 100,但我无法获取我尝试过“currentCondition.weatherDesc”的天气描述,然后得到输出“Object” : 目的”。而不是“小雨”我如何从txt文件中获取值“小雨”?
最佳答案
weatherDesc
是一个对象本身的数组,因此尝试 currentCondition.weatherDesc[0].value
总体来说:
data.current_condition[0].weatherDesc[0].value
关于javascript - 从 jQuery Whatweather 获取描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20454322/