mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
实现启动splash画面,实现天历史数据的处理和数据库存贮
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <common/Spdlogger.h>
|
||||
|
||||
using njson = nlohmann::json;
|
||||
|
||||
@@ -53,26 +54,36 @@ class JSON
|
||||
public:
|
||||
static bool load(std::string jsonfile, njson& json);
|
||||
|
||||
|
||||
static bool parse(std::string jsonstr, njson& json);
|
||||
|
||||
template <typename T>
|
||||
static void read(njson& json, std::string k, T& v)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (json.contains(k)) { v = json.at(k).get<T>(); }
|
||||
}
|
||||
catch (const nlohmann::detail::exception& e)
|
||||
{
|
||||
std::cout << "JSON read error: k=" << k << ", err=" << e.what() << std::endl;
|
||||
}
|
||||
try { if (json.contains(k)) { v = json.at(k).get<T>(); } }
|
||||
catch (const nlohmann::detail::exception& e) { Spdlogger::info("JSON read error: k={}, err={}", k, e.what()); }
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T read(njson& json, std::string k)
|
||||
{
|
||||
T v {};
|
||||
try { if (json.contains(k)) { v = json.at(k).get<T>(); } }
|
||||
catch (const nlohmann::detail::exception& e) { Spdlogger::info("JSON read error: k={}, err={}", k, e.what()); }
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T get(njson& json)
|
||||
{
|
||||
T v {};
|
||||
try { v = json.get<T>(); }
|
||||
catch (const nlohmann::detail::exception& e) { Spdlogger::info("JSON read error: err={}, json={}", e.what(), json.dump()); }
|
||||
return v;
|
||||
}
|
||||
|
||||
static std::string readStr(njson& json, std::string k);
|
||||
|
||||
static void parse(std::string jsonstr, std::vector<std::string>& vd);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user