42 lines
1.6 KiB
C++
42 lines
1.6 KiB
C++
#ifndef NLOHMANN_JSON_WRAPPER_H
|
||
#define NLOHMANN_JSON_WRAPPER_H
|
||
|
||
#include "json.hpp"
|
||
#include "GdCPP_Exports.h"
|
||
/**
|
||
* @addtogroup ksjson
|
||
* @{
|
||
* @addtogroup nlohmann_json_wrapper
|
||
* @brief 引用nlohmann::json的类和异常等。
|
||
* @details
|
||
* @{
|
||
*/
|
||
|
||
/// \brief 将nlohmann::json定义为jsonobj,简化掉namespace的访问。
|
||
///
|
||
/// 本来想用json,但语义不够明确。因此采用了一个跟Qt的QJsonObject近似的名称,
|
||
/// 表示可以替代QJsonObject,实际上这个类的功能很强大,可以完全替代QJsonObject、QJsonValue、QJsonArray,
|
||
/// 可以替代QJsonDocument的部分功能,甚至也能部分替代QVariant用。
|
||
using jsonobj = nlohmann::ordered_json;
|
||
|
||
// 以下定义用于简化json的异常类型的访问
|
||
using json_exception = nlohmann::json::exception;
|
||
using json_parse_err = nlohmann::json::parse_error;
|
||
using json_invalid_iterator = nlohmann::json::invalid_iterator;
|
||
using json_type_error = nlohmann::json::type_error;
|
||
using json_out_of_range = nlohmann::json::out_of_range;
|
||
using json_other_error = nlohmann::json::other_error;
|
||
|
||
// 判断数据类型是否可以做json的key
|
||
template <typename T> struct JsonKey;
|
||
template <> struct JsonKey<const std::string&> { typedef const std::string& Type; };
|
||
template <> struct JsonKey<const char * > { typedef const char* Type; };
|
||
|
||
// 判断类型是否可以做数组长度
|
||
template <typename T> struct ArraySizeT;
|
||
template <> struct ArraySizeT<int> { typedef int Type; };
|
||
template <> struct ArraySizeT<size_t> { typedef size_t Type; };
|
||
/** @} nlohmann_json_wrapper */
|
||
/** @} ksjson */
|
||
#endif // NLOHMANN_JSON_WRAPPER_H
|