20using json = nlohmann::json;
68bool Get(
const json& j,
const std::string& name,
T& t)
70 auto iter = j.find(name);
82 catch (nlohmann::detail::exception& e)
85 log_err(
"json取值失败({}): {}", name, e.what());
100 catch (nlohmann::detail::exception& e)
103 log_err(
"json取值失败: {}", e.what());
113 j.dump(4,
' ',
false, nlohmann::json::error_handler_t::replace);
132bool SaveFile(
const json& j, std::string_view path_name,
bool binary =
false);
138 template<
typename T,
size_t N>
141 for (
size_t i = 0; i <
N; ++i)
143 arr[i] = j.
at(i).get<
T>();
147 template<
typename T,
size_t N>
151 for (
size_t i = 0; i <
N; ++i)
constexpr T & at(size_t i)
类似std::array,增加xyzw、wh等成员访问
void SetLog(bool open)
设置是否提示输出日志(请直接使用DisableLog来关闭后,自动恢复)
bool Cast(const json &j, T &t)
从json返回值,不存在则返回false,打印日志
json Parse(BufferView buf, bool binary=false)
从 内存 构建json对象
json ParseString(std::string_view str)
从 字符串 构建json对象
bool Get(const json &j, const std::string &name, T &t)
从json返回子元素值,不存在则返回false,打印日志
json ParseFile(std::string_view path_name, bool binary=false)
从 文件 构建json对象
std::string Dump(json &j)
dump
bool SaveFile(const json &j, std::string_view path_name, bool binary=false)
保存到文件
void from_json(const json &j, Array< T, N > &arr)
void to_json(json &j, const Array< T, N > &arr)