JSON 输入
正在加载编辑器…
生成的 C++
Configuration
输入 JSON 数据以生成 C++ 类
具有 JSON 序列化支持的现代 C++ 类
从 JSON 数据结构生成 C++ 类
输入 JSON 数据以生成 C++ 类
具有 JSON 序列化支持的现代 C++ 类
使用此 JSON 转 C++ 生成器,可从 JSON 示例生成 C++ 类/结构体,适用于服务端与原生应用。
步骤 1 – 粘贴 JSON 示例
导入 从文件、URL 或示例数据加载 JSON。步骤 2 – 选择 C++ 生成选项
类名。std::optional)。std::vector 与嵌套类型)。步骤 3 – 检查生成的代码
根类型名称、空值处理策略以及可选的框架选项。步骤 4 – 在 C++ 中使用生成类型
步骤 5 – 复制或下载
快速提示
std::optional。// JSON 输入
{
"id": 123,
"name": "Maeve Winters",
"email": "[email protected]",
"active": true,
"roles": ["admin", "editor"],
"metadata": { "plan": "pro" },
"createdAt": "2024-03-01T10:15:00Z",
"score": 99.5,
"notes": null
}
// 生成的 C++ 模型(简化)
struct Metadata {
std::string plan;
};
struct Root {
int id;
std::string name;
std::optional<std::string> email;
bool active;
std::vector<std::string> roles;
Metadata metadata;
std::string createdAt;
double score;
std::nullptr_t notes;
};探索更多可与本 JSON 转 C++ 生成器配合使用的 JSON 与 Schema 工具。
生成器创建具有构造函数、getter/setter 方法的现代 C++ 类,支持 JSON 序列化/反序列化功能,并支持 STL 容器和智能指针。
生成的类包含 toJson() 和 fromJson() 方法,可与 nlohmann/json 库一起用于 JSON 数据序列化和反序列化。
生成的代码与 C++11 及更高版本兼容,使用 std::string、std::vector 和其他 STL 容器,具有可选的智能指针支持。
嵌套对象生成相应的类定义,数组映射到 std::vector,支持复杂的嵌套数据结构。