JSON 輸入
正在載入編輯器…
生成的 C++
Configuration
輸入 JSON 資料以產生 C++ 類別
現代 C++ 類別與 JSON 序列化支援
從 JSON 資料結構產生 C++ 類別
輸入 JSON 資料以產生 C++ 類別
現代 C++ 類別與 JSON 序列化支援
使用此 JSON 轉 C++ 產生器,可從 JSON 範例產生 C++ class/struct,適合後端服務與原生應用。
步驟 1 – 貼上 JSON 範例
匯入 從檔案、URL 或示例資料載入 JSON。步驟 2 – 選擇 C++ 產生選項
Class Name。std::optional)。std::vector 與巢狀型別)。步驟 3 – 檢查產生的程式碼
根型別名稱、null 處理策略與可選的框架選項。步驟 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 工具。
產生器會建立現代 C++ 類別,包含建構子、getter/setter、JSON 序列化/反序列化功能,並支援 STL 容器與智慧指標。
產生的類別包含 toJson() 與 fromJson() 方法,並可搭配 nlohmann/json 函式庫進行 JSON 序列化與反序列化。
產生的程式碼相容於 C++11 及以上版本,使用 std::string、std::vector 等 STL 容器,並提供可選的智慧指標支援。
巢狀物件會產生對應的類別定義,陣列會對應到 std::vector,可支援複雜的巢狀資料結構。