如何从一个JSON对象string自动生成一个C#类文件
鉴于以下JSON对象,
form = { "name": "", "address": { "street": "", "city": "", "province": "", "postalCode": "", "country": "" }, "phoneDay": "", "phoneCell": "", "businessName": "", "website": "", "email": "" } 什么是自动生成以下C#类的工具?
 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; } } 
我们已经看了这些问题:
从JSON模式生成C#类问是关于JSON模式,这可能是一种在路上使用的方法。
生成的Json对象的C#类的优点和缺点
三个选项:
- 
使用免费的json2csharpnetworking工具,无需安装任何东西。 
- 
如果您在Visual Studio中具有Web Essentials ,请使用编辑>select性粘贴>将JSON粘贴为类。 
- 
使用免费的jsonclassgenerator.exe 
优点和缺点:
- jsonclassgenerator转换为PascalCase,但其他人不。
Visual Studio 2012(安装了ASP.NET和Web Tools 2012.2 RC)本机支持。
Visual Studio 2013开始有这个内置的。
  (图片提供: robert.muehsig )
  (图片提供: robert.muehsig ) 
如果您将Web Essentials安装到Visual Studio中,您可以转到Edit => Past special =>将JSON粘贴为类。
这可能是最简单的。
Web Essentials: http : //vswebessentials.com/