mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
实现MQTT功能, 修改HTTP接口
This commit is contained in:
@@ -54,19 +54,17 @@ public:
|
||||
static bool load(std::string jsonfile, NJsonNode& json)
|
||||
{
|
||||
std::ifstream ifs(jsonfile);
|
||||
if (ifs.is_open())
|
||||
{
|
||||
ifs >> json;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (!ifs.is_open()) { return false; }
|
||||
try { ifs >> json; }
|
||||
catch (nlohmann::json::parse_error& e) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse(std::string jsonstr, NJsonNode& json)
|
||||
{
|
||||
try
|
||||
{
|
||||
json = NJsonNode::parse(jsonstr);
|
||||
if (!jsonstr.empty()) { json = NJsonNode::parse(jsonstr); }
|
||||
}
|
||||
catch (nlohmann::json::parse_error& e)
|
||||
{
|
||||
@@ -75,11 +73,6 @@ public:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool contains(NJsonNode& json, std::string key)
|
||||
{
|
||||
return json.contains("database");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void read(NJsonNode& json, std::string k, T& v)
|
||||
@@ -90,7 +83,7 @@ public:
|
||||
}
|
||||
catch (const nlohmann::detail::exception& e)
|
||||
{
|
||||
std::cout << "JSON read error: " << e.what() << std::endl;
|
||||
std::cout << "JSON read error: k=" << k << ", err=" << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user