Building a JSON Configuration Section

后端 未结 5 1524
轮回少年
轮回少年 2021-02-18 20:37

Is there a way to have configuration sections written in JSON instead of XML?

Let\'s suppose I have the following ConfigurationSection:

publ         


        
5条回答
  •  天命终不由人
    2021-02-18 21:04

    // To convert an XML node contained in string xml into a JSON string

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xml);
    string jsonText = JsonConvert.SerializeXmlNode(doc);
    

    // To convert JSON text contained in string json into an XML node

    XmlDocument doc = JsonConvert.DeserializeXmlNode(json);
    

    Documentation here: Converting between JSON and XML with Json.NET

提交回复
热议问题