Blinker获取3天预报天气返回数据日期有问题
本帖最后由 shory 于 2021-3-9 10:43 编辑今天是3月9日,获取的3天天气预报信息:
Blinker.attachWeatherForecast(weatherForecastData);返回的是从2月28日开始的3天:
09:59:23.216 ->
{"city":"襄阳市","province":"湖北","<font color="#ff0000">updateTime":"2021-02-28 10:23:50</font>","forecasts":[{"date":"<font color="#ff0000">2021-02-28</font>","week":"7","dayweather":"小雨","nightweather":"小雨","daytemp":"7","nighttemp":"5","daywind":"东北","nightwind":"东北","daypower":"≤3","nightpower":"≤3"},{"date":"<font color="#ff0000">2021-03-01</font>","week":"1","dayweather":"小雨","nightweather":"晴","daytemp":"8","nighttemp":"2","daywind":"北","nightwind":"北","daypower":"≤3","nightpower":"≤3"},{"date":"2021-03-02","week":"2","dayweather":"多云","nightweather":"多云","daytemp":"14","nighttemp":"3","daywind":"东","nightwind":"东","daypower":"≤3","nightpower":"≤3"},{"date":"<font color="#ff0000">2021-03-03</font>","week":"3","dayweather":"多云","nightweather":"多云","daytemp":"17","nighttemp":"7","daywind":"南","nightwind":"南","daypower":"≤3","nightpower":"≤3"}]}代码:
void weatherForecastData(const String & data)
{
const char* dayWeather;
const char* nightWeather;
const char* tempHigh;
const char* tempLow;
// BLINKER_LOG("weather: ", data);
DynamicJsonDocument jsonBuffer(1536);
DeserializationError error = deserializeJson(jsonBuffer, data);
if (error) {
BLINKER_LOG(F("deserializeJson() failed: "));
BLINKER_LOG("没有获取到天气信息");
return;
}
JsonArray doc = jsonBuffer["forecasts"].as<JsonArray>();
dayWeather =doc["dayweather"];
nightWeather =doc["nightweather"];
tempHigh =doc["daytemp"];
tempLow = doc["nighttemp"];
BLINKER_LOG("输出天气信息:");
BLINKER_LOG("dayWeather: ", dayWeather);
BLINKER_LOG("nightWeather: ", nightWeather);
BLINKER_LOG("tempHigh: ", tempHigh);
BLINKER_LOG("tempLow: ", tempLow);
}
解析JSON没有问题。
新的天气接口已经上线,请使用dev3.0分支文档:https://diandeng.tech/doc/weather-and-air
奈何col 发表于 2021-3-9 11:28
新的天气接口已经上线,请使用dev3.0分支文档:https://diandeng.tech/doc/weather-and-air
...
新的接口有示例程序吗?我之前的程序好像不能获取天气信息了:hug: 3137234383 发表于 2021-3-16 15:11
新的接口有示例程序吗?我之前的程序好像不能获取天气信息了
更新lib后查看例程 奈何col 发表于 2021-3-16 16:25
更新lib后查看例程
好的,已解决:victory:
页:
[1]