Erstellen eines JSON-Konfigurationsabschnitts

Gibt es eine Möglichkeit, Konfigurationsabschnitte in JSON anstelle von XML zu schreiben?

Nehmen wir an, ich habe die folgendenConfigurationSection:

public class UsersConfig : ConfigurationSection {

      [ConfigurationProperty("users",
                             IsRequired = false)]
      public UserCollection Users {
           get { return this["users"] as UserCollection; }
      }
}

[ConfigurationCollection(typeof(UserElement),
     AddItemName = "user"]
public class UsersCollection : ConfigurationElementCollection {
      protected override ConfigurationElement CreateNewElement() {
            return new UserElement();
      }

      protected override object GetElementKey(ConfigurationElement element) {
            return ((UserElement)element).Name;
      }
}

public class UserElement : ConfigurationElement {

     [ConfigurationProperty("name",
                            IsRequired = true,
                            IsKey = true)]
     public string Name {
          get { return this["name"] as string; }
          set { this["name"] = value; }
     }
}

Ich kann dann den folgenden XML-Konfigurationsabschnitt erstellen:

<users-config>
      <users>
            <user name="Matt458" />
            <user name="JohnLennon" />
      </users>
</users-config>

Was ich erreichen möchte, ist @ zu pflegdie gleiche UsersConfig Klasse, aber anstatt es XML zuzuordnen, möchte ich es einem JSON zuordnen:

{
    "users": [
        {
            "name": "Matt458"
        },
        {
             "name": "JohnLennon"
        }
    ]
}

Antworten auf die Frage(10)

Ihre Antwort auf die Frage