考虑这个 JSON:
{
"firstName": "John",
"lastName": "Doe",
"homeAddress": {
"streetAddress": "123 Main St",
"city": "Boston",
"state": "MA",
"postalCode": "02110"
},
"employmentInfo": {
"employerName": "ABC, Co.",
"phoneNumber": "617-555-5555"
}
}
在 VS 中,我可以使用“编辑 > 选择性粘贴”中的“将 JSON 粘贴为类”。这是结果:
public class Rootobject
{
public string firstName { get; set; }
public string lastName { get; set; }
public Homeaddress homeAddress { get; set; }
public Employmentinfo employmentInfo { get; set; }
}
public class Homeaddress
{
public string streetAddress { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postalCode { get; set; }
}
public class Employmentinfo
{
public string employerName { get; set; }
public string phoneNumber { get; set; }
}
请注意以下几点:1.) 类名均以大写字母开头,然后全部小写,2.) 属性均为小驼峰命名法。
1号没有任何意义。为什么会这样,有官方原因吗?第二个是有道理的,但我希望能够改变行为,这样我的编译器就不会抱怨我的属性命名错误。
有没有办法调整这种行为?
我自己没有找到在 Visual Studio 中配置此功能的方法。
如果您不介意打开浏览器窗口并从那里复制,QuickType 可以节省大量时间
https://app.quicktype.io/?l=csharp https://app.quicktype.io/?l=csharp
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)