读取.yaml文件和json文件

读取.yaml文件和json文件,第1张

读取.yaml文件和json文件

yaml文件:

	auto label_cls = YAML::LoadFile("label.yaml");
    std::vector m_label_cls;
    if (label_cls["label"])
    {
        m_label_cls = label_cls["label"].as>();
    } 

取为.yaml数据时类型:

 .as();
 .as();
 .as();
 .as();
 .as>()

if (config["face"]["face_enable"])
            opt.is_face_enable = config["face"]["face_enable"].as();

写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(); //引用
 auto command = req_js["Command"].get();

auto& SourceAndRule = req_js["SourceAndRule"];

 for (auto Item: SourceAndRule["Item"])
{
  auto& termId = Item["TermId"].get_ref();
}

if (req_js.find("Type") != req_js.end())
{
  cam_it->m_urlType = req_js["Type"].get(); // 0 for realplay, 1 for replay
  taskInfo.m_urlType = req_js["Type"].get();
}


 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();
    if (Point.find("y") != Point.end())
        cvPoint.y = Point["y"].get();
    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);;

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5670954.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存