JSON到C#类-当JSON具有不同的节点名称时如何创建c#类作为列表或数组

 收藏
下面的JSON和C#对象有效,但它是丑陋的c#对象,   在50个州中,它看起来更加丑陋且难以管理。寻找清洁剂   创建c#对象并生成相同JSON的方法。我不能   修改JSON,因为它是由插件定义的。
    {
      "main_settings": {
        "width": "700",
        "background_color": "#FFFFFF",  
        "fade_time": 0.1,
        "link_text": "View Website"
      },
      "state_specific": {
        "AB": {
          "name": "Alberta",
          "description": "default",
          "color": "default",
          "hover_color": "default",
          "url": "default"
        },
        "AK": {
          "name": "Alaska",
          "description": "default",
          "color": "default",
          "hover_color": "default",
          "url": "default"
        },
        "AL": {
          "name": "Alabama",
          "description": "default",
          "color": "default",
          "hover_color": "default",
          "url": "default"
        },
        "AR": {
          "name": "Arkansas",
          "description": "default",
          "color": "default",
          "hover_color": "default",
          "url": "default"
        },
        "AZ": {
          "name": "Arizona",
          "description": "default",
          "color": "default",
          "hover_color": "default",
          "url": "default"
        },

        "YT": {
          "name": "Yukon",
          "description": "default",
          "color": "default",
          "hover_color": "default",
          "url": "default"
        }
      }

    }
C#类-创建相同的JSON。可能是处理列表和数组的更好方法
    public class MainSettings
    {
        public string width { get; set; }
        public string background_color { get; set; }
        public double fade_time { get; set; }
        public string link_text { get; set; }
    }

    public class AB
    {
        public string name { get; set; }
        public string description { get; set; }
        public string color { get; set; }
        public string hover_color { get; set; }
        public string url { get; set; }
    }

    public class AK
    {
        public string name { get; set; }
        public string description { get; set; }
        public string color { get; set; }
        public string hover_color { get; set; }
        public string url { get; set; }
    }

    public class AL
    {
        public string name { get; set; }
        public string description { get; set; }
        public string color { get; set; }
        public string hover_color { get; set; }
        public string url { get; set; }
    }

    public class AR
    {
        public string name { get; set; }
        public string description { get; set; }
        public string color { get; set; }
        public string hover_color { get; set; }
        public string url { get; set; }
    }

    public class AZ
    {
        public string name { get; set; }
        public string description { get; set; }
        public string color { get; set; }
        public string hover_color { get; set; }
        public string url { get; set; }
    }

    public class YT
    {
        public string name { get; set; }
        public string description { get; set; }
        public string color { get; set; }
        public string hover_color { get; set; }
        public string url { get; set; }
    }

    public class StateSpecific
    {
        public AB AB { get; set; }
        public AK AK { get; set; }
        public AL AL { get; set; }
        public AR AR { get; set; }
        public AZ AZ { get; set; }
        public YT YT { get; set; }
    }

    public class RootObject
    {
        public MainSettings main_settings { get; set; }
        public StateSpecific state_specific { get; set; }
    }
回复