44 lines
620 B
C++
44 lines
620 B
C++
/**
|
|
* @file dl_json.h
|
|
* @brief json格式相关
|
|
*
|
|
*
|
|
* @version 1.0
|
|
* @author lveyou
|
|
* @date 23-07-22
|
|
*
|
|
* @note 基于 nlohmann::json
|
|
*/
|
|
#pragma once
|
|
|
|
#include <json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
namespace dl::Json
|
|
{
|
|
|
|
/**
|
|
* @brief 从 文件 构建json对象
|
|
* @note 失败返回null,并输出日志
|
|
*/
|
|
json Parse(std::string_view path_name);
|
|
|
|
|
|
/**
|
|
* @brief 从json返回值,不存在则返回false,并且不进行任何操作
|
|
*/
|
|
template<typename T>
|
|
bool Get(const json& j, const std::string& name, T& t)
|
|
{
|
|
auto iter = j.find(name);
|
|
if (iter == j.end())
|
|
return false;
|
|
t = *iter;
|
|
return true;
|
|
}
|
|
|
|
|
|
}
|
|
|