Blinker获取3天预报天气返回数据日期有问题-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1683|回复: 4

[已解答] Blinker获取3天预报天气返回数据日期有问题

[复制链接]
发表于 2021-3-9 10:09 | 显示全部楼层 |阅读模式
本帖最后由 shory 于 2021-3-9 10:43 编辑

今天是3月9日,获取的3天天气预报信息:
  1. Blinker.attachWeatherForecast(weatherForecastData);
复制代码
返回的是从2月28日开始的3天:
  1. 09:59:23.216 -> [33893]
复制代码
  1. {"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[0]["dayweather"];
    nightWeather =  doc[0]["nightweather"];
    tempHigh =  doc[0]["daytemp"];
    tempLow = doc[0]["nighttemp"];

    BLINKER_LOG("输出天气信息:");
    BLINKER_LOG("dayWeather: ", dayWeather);
    BLINKER_LOG("nightWeather: ", nightWeather);
    BLINKER_LOG("tempHigh: ", tempHigh);
    BLINKER_LOG("tempLow: ", tempLow);

}

解析JSON没有问题。

发表于 2021-3-9 11:28 | 显示全部楼层
新的天气接口已经上线,请使用dev3.0分支文档:https://diandeng.tech/doc/weather-and-air
发表于 2021-3-16 15:11 | 显示全部楼层
奈何col 发表于 2021-3-9 11:28
新的天气接口已经上线,请使用dev3.0分支文档:https://diandeng.tech/doc/weather-and-air
...

新的接口有示例程序吗?我之前的程序好像不能获取天气信息了

点评

更新lib后查看例程  详情 回复 发表于 2021-3-16 16:25
发表于 2021-3-16 16:25 | 显示全部楼层
3137234383 发表于 2021-3-16 15:11
新的接口有示例程序吗?我之前的程序好像不能获取天气信息了

更新lib后查看例程
发表于 2021-3-18 11:42 | 显示全部楼层
奈何col 发表于 2021-3-16 16:25
更新lib后查看例程

好的,已解决
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 13:32 , Processed in 0.071781 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表