Given the following JSON object,

form = {
  "name": "",
  "address": {
    "street": "",
    "city": "",
    "province": "",
    "postalCode": "",
    "country": ""
  },
  "phoneDay": "",
  "phoneCell": "",
  "businessName": "",
  "website": "",
  "email": ""
}

what is a tool to auto-generate the following C# class?

public class ContactInfo
{
    public string Name { get; set; }
    public Address Address { get; set; }
    public string PhoneDay { get; set; }
    public string PhoneCell { get; set; }
    public string BusinessName { get; set; }
    public string Website { get; set; }
    public string Email { get; set; }
}

public class Address
{
    public string Street { get; set; }
    public string City { get; set; }
    public string Province { get; set; }
    public string PostalCode { get; set; }
    public string Country { get; set; }
}

我们已经研究了这些问题:

Generate C# classes from JSON Schema Is asking about JSON Schemas which may be an approach to use down the road.

Benefits and drawbacks of generated C# classes for Json objects

推荐答案

Five options:

Pros and Cons:

Json相关问答推荐

在 json 对象中存储多个键:值对

具有 (RegEx) 模式的 json-schema 中的枚举

Oracle json 对象的最后一个值不在引号中

无法在Kotlin 中解析JSONObject

使用带有逗号的字段名称构建 struct

为什么JsonConvert反序列化对象以int但不长失败

如何在 Django 的模板语言中获取 json 键和值?

将嵌套的 JSON 对象规范化为 Pandas 数据框

如何为所有 API 端点全局设置 http.ResponseWriter Content-Type 标头?

一起使用 Argparse 和 Json

将 JSON 数据导入 Google 表格

将带有数据和文件的 JSON 发布到 Web Api - jQuery / MVC

Json.Net:用于自定义命名的 JsonSerializer-Attribute

Golang struct 的 XML 和 JSON 标签?

区分字符串和列表的 Pythonic 方式是什么?

JSON 使用 simplejson 序列化 Django 模型

将序列化表单的数据转换为 json 对象

有没有办法在 angular.json 中扩展配置?

AJAX 将 JavaScript 字符串数组发布到 JsonResult 作为 List 总是返回 Null?

如何在 postgresql 9.3 中循环 JSON 数组