Is there any way to JSON.NET-serialize a subclass of List that also has extra properties?

前端 未结 3 1973
没有蜡笔的小新
没有蜡笔的小新 2020-12-17 19:26

Ok, we\'re using Newtonsoft\'s JSON.NET product, which I really love. However, I have a simple class structure for hierarchical locations that look roughly like this...

3条回答
  •  感动是毒
    2020-12-17 20:14

    Usually when I find myself fighting something like this it tells me I should consider another approach. In this case, I would recommend the following view model structure as an alternative:

    public class Location
    {
        public bool IsExpanded { get; set; }
        public string Name { get; set; }
        public List Locations { get; set; }
    }
    
    public class ViewModel
    {
        public List RootLocations { get; set; }
    }
    

提交回复
热议问题