Easy way to convert a Dictionary to xml and vice versa

前端 未结 6 1632
北海茫月
北海茫月 2020-11-30 22:13

Wondering if there is a fast way, maybe with linq?, to convert a Dictionary into a XML document. And a way to convert the xml back to a di

6条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 23:16

      Dictionary myDictionary = new Dictionary();
      myDictionary.Add("key", "value");
      myDictionary.Add("key2", "value");
      var myJson = JsonConvert.SerializeObject(myDictionary);
      var myXml = JsonConvert.DeserializeXNode(myJson.ToString(),"root");
      Console.WriteLine(myXml.ToString());
      Console.Read();
    

提交回复
热议问题