json-to-go.input
json-to-go.output
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
public class Profile
{
[JsonProperty("age")]
public int Age { get; set; }
[JsonProperty("city")]
public string? City { get; set; }
}
public class RootObject
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string? Name { get; set; }
[JsonProperty("active")]
public bool Active { get; set; }
[JsonProperty("score")]
public double Score { get; set; }
[JsonProperty("tags")]
public List<string>? Tags { get; set; }
[JsonProperty("profile")]
public Profile Profile { get; set; }
}关于 JSON to C#
.NET 开发中对接 JSON 接口需要手写大量 C# 类,本工具在浏览器本地解析样例 JSON,自动生成完整的 C# 类:字段名转为 PascalCase,嵌套对象拆分为独立 class,数组推断为 List<T>,支持 nullable 引用类型和 Newtonsoft.Json / System.Text.Json 的 JsonProperty 特性。数据不上传。
使用方法
- 打开 JSON to C# 工具页面
- 根据需求输入或粘贴数据到输入区域
- 查看实时处理结果,使用复制按钮获取输出
使用场景
- 对接 REST 接口 — 把接口 JSON 转成 C# 类,配合 HttpClient/RestSharp 做反序列化。
- EF Core 实体 — 从数据库 JSON 样例生成实体类,用于 Entity Framework Core 映射。
- Unity 配置建模 — 为 Unity 游戏配置 JSON 生成类型安全的 C# 模型。
- Azure Function 输入 — 快速生成输入模型类,用于 Azure Function 的 HTTP Trigger。
常见问题
Newtonsoft 和 System.Text.Json 有什么区别?
Newtonsoft.Json 使用 [JsonProperty],System.Text.Json 使用 [JsonPropertyName]。按项目依赖选择。
null 值怎么处理?
null 值推断为 object?,建议用非空样例获得更精确的类型。
nullable 引用类型是什么?
C# 8+ 特性,开启后 string 等引用类型字段会标记为可空(string?),编译器做空值检查。
嵌套对象怎么处理?
每个嵌套对象生成独立的 class,结构清晰可复用。
评论与讨论
💬 评论仅保存在你的浏览器本地,切换设备后不可见。配置 Giscus 后可支持云端评论。