实现MQTT功能, 修改HTTP接口

This commit is contained in:
lixiaoyuan
2025-09-04 19:31:04 +08:00
parent 61ed4f355f
commit d81bcd9983
30 changed files with 2029 additions and 697 deletions

View File

@@ -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;
}
}