我有以下的json,我想序列化以在一个POST请求中发送。
{
"Details
": {
"title": "Mr",
"firstName": "Jimmy",
"lastName": "Jameson",
"dateOfBirth": "20.01.1994",
},
"meterreading": {
"mnrr": "10234567891",
"Longmeterread ": "12345",
"Shortmeterread ": "23456",
"Medtmeterread ": "34567"
}
},
"otherdata": {
"xyz": "somedata",
"lmnop ": "more",
"qrst ": "even more",
"uvwz ": "last one"
}
I have created the following class to represent it in Visual Studio:
{
public class MainObjectModel
{
public Details Details { get; set; }
public meterreading meterreading { get; set; }
public otherdata otherdata { get; set; }
}
public class Details
{
public string _title = "Mr";
public string _firstName = "Jimmy";
public string _lastName = "Jameson";
public string _dateOfBirth = "20.01.1994";
}
public class meterreading
{
public string _mnrr = "10234567891";
public string _Longmeterread = "12345";
public string _Shortmeterread = "23456";
public string _Medtmeterread = "34567";
}
public class otherdata
{
public string xyz = "somedata";
public string lmnop = "more";
public string qrst = "even more";
public string uvwz = "last one";
}
}
当我实例化MainObjectModel然后序列化时,每个类都返回为null?我试着通过删除MainObjectModel部分来简化类,但它只序列化了第一部分,而且它没有部分的标题?我如何在VS中安排该类以上述格式返回json?先谢谢你的帮助。
的 "details"
是破碎的。
# wrong
"Details
": {
# better
"Details": {