yaml文件:
auto label_cls = YAML::LoadFile("label.yaml");
std::vector<std::string> m_label_cls;
if (label_cls["label"])
{
m_label_cls = label_cls["label"].as<std::vector<std::string>>();
}
取为.yaml数据时类型:
.as<bool>();
.as<int>();
.as<std::string>();
.as<float>();
.as<std::vector<std::string>>()
if (config["face"]["face_enable"])
opt.is_face_enable = config["face"]["face_enable"].as<bool>();
写json报文并发出去
nlohmann::json js_response;
js_response["EventType"] = "app_task_config";
js_response["Result"]["code"] = 0;
js_response["Result"]["Desc"] = "";
SimpleWeb::CaseInsensitiveMultimap header;
header.emplace("Content-Type", "application/json");
response->write(js_response.dump(), header);
解析json报文
auto& taskId = req_js["TaskId"].get_ref<const std::string&>(); //引用
auto command = req_js["Command"].get<int>();
auto& SourceAndRule = req_js["SourceAndRule"];
for (auto Item: SourceAndRule["Item"])
{
auto& termId = Item["TermId"].get_ref<const std::string&>();
}
if (req_js.find("Type") != req_js.end())
{
cam_it->m_urlType = req_js["Type"].get<int>(); // 0 for realplay, 1 for replay
taskInfo.m_urlType = req_js["Type"].get<int>();
}
if(RuleProperty["Point"].empty()) //判空
for (auto& Point: RuleProperty["Point"])
{
cvPoint = cv::Point(0.0);
if (Point.find("x") != Point.end())
cvPoint.x = Point["x"].get<int>();
if (Point.find("y") != Point.end())
cvPoint.y = Point["y"].get<int>();
cvPointVec.push_back(cvPoint);
}
json转string js_response.dump()
string转json格式
std::string taskInfo = task->m_taskInfo;
nlohmann::json req_js = nlohmann::json::parse(taskInfo);;