JSON 輸入
正在載入編輯器…
生成的 C
Configuration
輸入 JSON 資料以產生 C struct
包含管理函式的記憶體安全 struct
從 JSON 資料結構產生 C struct
輸入 JSON 資料以產生 C struct
包含管理函式的記憶體安全 struct
使用此 JSON 轉 C 產生器,可從 JSON 範例快速產生 C struct,適合嵌入式、C 函式庫與底層整合。
步驟 1 – 貼上 JSON 範例
匯入 從檔案、URL 或示例資料載入 JSON。步驟 2 – 選擇 C struct 選項
Struct Name(例如 Root)。json-c)。步驟 3 – 檢查產生的程式碼
根型別名稱、null 處理策略與可選的框架選項。步驟 4 – 整合到 C 專案
.h/.c 檔加入建置,並在需要處 include 其標頭。步驟 5 – 複製或下載
快速提示
// 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(簡化)
typedef struct Metadata {
char* plan;
} Metadata;
typedef struct Root {
int id;
char* name;
char* email; // JSON 中可能為 null
int active;
char** roles;
int roles_count;
Metadata metadata;
char* createdAt;
double score;
void* notes;
} Root;探索更多可與本 JSON 轉 C 產生器搭配使用的 JSON 與 Schema 工具。
產生器會建立標準 C struct 定義,包含記憶體管理函式(create 與 free)、支援基本資料型別對應,並遵循 C 命名慣例。
產生的程式碼包含 create_ 與 free_ 函式,用於安全的記憶體配置與釋放。字串欄位需要手動配置記憶體。
選擇「JSON‑C」框架可產生與 json-c 函式庫相容的程式碼,並包含適當的標頭檔引用。
陣列會對應到 void** 指標,巢狀物件會對應到 void* 指標。需要依實際需求進行型別轉換與記憶體管理。