如何自动生成一个JSON对象字符串一个C#类文件 [英] How to auto-generate a C# class file from a JSON object string

查看:300
本文介绍了如何自动生成一个JSON对象字符串一个C#类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

什么是自动生成下面的C#类的工具吗?

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; }
}

我们已经看了这些问题:

We have already looked at these questions:

生成JSON模式 C#类是问JSON架构这可能是使用的道路的一种方法。

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

<一个href=\"http://stackoverflow.com/questions/9229237/benefits-and-drawbacks-of-generated-c-sharp-classes-for-json-objects\">Benefits和JSON的生成的C#类的弊端对象

推荐答案

三个选项:


  • 使用免费的 json2csharp 网络,而无需安装任何工具。

  • Use the free json2csharp web tool without installing anything.

如果您有网络要点在Visual Studio 的,用作类编辑>粘贴>粘贴JSON。

If you have Web Essentials in Visual Studio, use Edit > Paste special > paste JSON as class.

使用免费的 jsonclassgenerator 的.exe

Use the free jsonclassgenerator.exe

优缺点:

  • jsonclassgenerator converts to PascalCase but the others do not.

这篇关于如何自动生成一个JSON对象字符串一个C#类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆