public class Vehicle
{
public String Manufacturer;
}
public class Train : Vehicle
{
public int MaxNumberOfWagons;
}
var aTrain = new Train();
aTrain.Manufacturer = "RailCorpMurica";
aTrain.MaxNumberOfWagons = 30;
var aTrainJson = serialiser.Serialise(aTrain);
//aTrainJson does not have the Manufacturer property?
我正在尝试将aTrain
序列化为json。结果包含MaxNumberOfWagons键和值。但制造不包括在内。
如何在不触及Vehicle
课程的情况下包含制造商?
答案 0 :(得分:0)
如何序列化对象?以下代码应该能够得到你想要的东西:
var aTrainJson = new JavaScriptSerializer().Serialize(aTrain);
确保添加对System.Web.Extension的引用。