我有一个从 Dictionary 继承的类,并且上面有几个属性。当我序列化它只序列化字典而不是属性。如果我有一个包含属性的负载,它会反序列化它们。如何让它序列化我的对象,包括属性?
public class Maintenance : Dictionary<string, dynamic>
{
public int PersonId { get; set; }
}
return JsonConvert.DeserializeObject<T>(jsonString); //Populates PersonId and all other properties end up in the dictionary.
return JsonConvert.SerializeObject(maintenance); //Only returns dictionary contents
Run Code Online (Sandbox Code Playgroud)
我很感激有关如何使序列化使用与反序列化似乎使用相同的行为的建议。