为“将JSON粘贴为类"配置类和成员名大小写(lowerCamelCase与UpperCamelCase).在Visual Studio中 [英] Configure class and member name casing (lowerCamelCase vs. UpperCamelCase) for "Paste JSON as Classes" in Visual Studio
问题描述
考虑此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.)属性全部为lowerCamelCase.
数字1没有任何意义.为什么会有这种行为,有正式的理由吗?数字2是有道理的,但我希望能够更改行为,以使我的编译器不会抱怨命名属性错误.
有没有办法调整这种行为?
我自己并没有遇到在Visual Studio中配置它的方法.
如果您不介意打开浏览器窗口并从那里进行复制,则QuickType可以节省大量时间
https://app.quicktype.io/?l=csharp >
Consider this JSON:
{
"firstName": "John",
"lastName": "Doe",
"homeAddress": {
"streetAddress": "123 Main St",
"city": "Boston",
"state": "MA",
"postalCode": "02110"
},
"employmentInfo": {
"employerName": "ABC, Co.",
"phoneNumber": "617-555-5555"
}
}
In VS I can use the "Paste JSON as Classes" from "Edit > Paste Special". This is what results:
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; }
}
Notice a couple things: 1.) the class names all have an initial uppercase character and then all lowercase, and 2.) the properties are all lowerCamelCase.
Number 1 doesn't make any sense. Why would it behave that way, is there an official reason? Number 2 makes sense, but I'd like to be able to change the behavior so my compiler doesn't complain about naming my properties wrong.
Is there a way to adjust this behavior?
I didn't come accross a way myself to configure this in Visual Studio.
If you don't mind opening a browser window and copying from there, QuickType is a HUGE time saver
https://app.quicktype.io/?l=csharp
这篇关于为“将JSON粘贴为类"配置类和成员名大小写(lowerCamelCase与UpperCamelCase).在Visual Studio中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!