好的,我们正在使用Newtonsoft的JSON.NET产品,我非常喜欢.但是,我有一个简单的类结构用于层次结构位置,看起来大致像这样......
public class Location
{
public string Name{ get; set; }
public LocationList Locations{ get; set; }
}
// Note: LocationList is simply a subclass of a List<T>
// which then adds an IsExpanded property for use by the UI.
public class LocationList : List<Location>
{
public bool IsExpanded{ get; set; }
}
public class RootViewModel
{
public LocationList RootLocations{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
...当我将它们序列化为JSON时,一切都很好,除了排除了LocationList类的IsExpanded属性.只序列化列表的内容.
现在,我想象的将是一个很好的格式.它本质上是相同的东西,如果LocationList它不是一个子类,List<Location>而只是一个常规对象,具有一个名为Items类型的属性List<Location>.
{
"Locations":
{
"IsExpanded": true,
"Items": …Run Code Online (Sandbox Code Playgroud)