JSON 到 C#

使用 Newtonsoft 或 System.Text.Json 從 JSON 產生 C# 類別或記錄。

免費在線 JSON 到 C# 類生成器

貼上 JSON 並取得帶有推斷類型、巢狀類別和陣列的 List<T> 的 C# 類別定義。選擇 POCO 類別或 C# 9+ 記錄、PascalCase 屬性名稱以及 Newtonsoft.Json 或 System.Text.Json 序列化屬性。

設定根類別名稱和可選命名空間,然後將產生的程式碼複製到您的 .NET 專案中。所有轉換都在您的瀏覽器中運行 - 不會上傳任何內容。

Frequently Asked Questions

What is the difference between POCO and record?
POCO (Plain Old CLR Object) classes are mutable reference types with get/set properties - the traditional C# approach. Records (C# 9+) are immutable by default with value-based equality. Use records for DTOs and API models; POCOs when you need mutable objects.
Which JSON library attributes are supported?
Dokall supports Newtonsoft.Json (JsonProperty attributes) and System.Text.Json (JsonPropertyName attributes). Choose based on your project's JSON serializer. System.Text.Json is the modern default in .NET Core 3+.
How are C# property names generated?
Property names use PascalCase by default, following C# conventions. JSON camelCase keys are converted: firstName becomes FirstName. You can set a namespace and root class name before generating.
How are arrays and nested objects handled?
JSON arrays become List<T> with the element type inferred. Nested objects become separate nested classes. Deep nesting produces nested class definitions within the root class.
Can I use this for Entity Framework models?
The generated classes work as DTOs and API models. Entity Framework entities typically need additional attributes (Key, Required, navigation properties) that are not inferred from JSON. Use the output as a starting point and add EF-specific annotations manually.