20using json = nlohmann::json;
66bool Get(
const json& j,
const std::string& name,
T& t)
68 auto iter = j.find(name);
80 catch (nlohmann::detail::exception& e)
83 log_err(
"json取值失败({}): {}", name, e.what());
98 catch (nlohmann::detail::exception& e)
101 log_err(
"json取值失败: {}", e.what());
111 j.dump(4,
' ',
false, nlohmann::json::error_handler_t::replace);
129 template<
typename T,
size_t N>
132 for (
size_t i = 0; i <
N; ++i)
134 arr[i] = j.
at(i).get<
T>();
138 template<
typename T,
size_t N>
142 for (
size_t i = 0; i <
N; ++i)
constexpr T & at(size_t i)
类似std::array,增加xyzw、wh等成员访问
void SetLog(bool open)
设置是否提示输出日志(请直接使用DisableLog来关闭后,自动恢复)
json ParseString(std::string_view str)
从 字符串 构建json对象
json ParseFile(std::string_view path_name)
从 文件 构建json对象
json Parse(BufferView buf)
从 内存 构建json对象
bool Get(const json &j, const std::string &name, T &t)
从json返回值,不存在则返回false,打印日志
std::string Dump(json &j)
dump
std::span< std::byte > BufferView
void from_json(const json &j, Array< T, N > &arr)
BufferView CreateBufferView(std::string_view str)
创建buffer视图
void to_json(json &j, const Array< T, N > &arr)