在 C# 开发中,处理 JSON 数据通常需要先定义复杂的 POCO (Plain Old CLR Object) 类。本工具支持一键将 JSON 示例数据 转换为高质量、类型严谨的 C# 类定义,并自动适配 Newtonsoft.Json 或 System.Text.Json 序列化规范。
本站工具深度适配了 C# 的语法特性与主流序列化框架:
int、long 与 double,确保大额数值不丢失精度。null 值,自动生成可空类型声明(如 int? 或 string?)。List<T> 或 T[]。[JsonProperty("name")] 特性标签。.NET Core/.NET 5+ 标准的 [JsonPropertyName("name")] 特性标签。snake_case (蛇形) 或 kebab-case 自动转换为 C# 标准的 PascalCase (大驼峰) 命名。{ get; set; } 自动属性或传统的成员字段。Root)。
.cs 文件中。原始 JSON:
{
"order_id": 9876543210,
"customer_name": "Gemini User",
"is_paid": true,
"items": ["Laptop", "Mouse"]
}
生成的 C# 代码 (System.Text.Json 风格):
using System.Text.Json.Serialization;
using System.Collections.Generic;
public class OrderInfo
{
[JsonPropertyName("order_id")]
public long OrderId { get; set; }
[JsonPropertyName("customer_name")]
public string CustomerName { get; set; }
[JsonPropertyName("is_paid")]
public bool IsPaid { get; set; }
[JsonPropertyName("items")]
public List<string> Items { get; set; }
}