Converting XML to a dynamic C# object

后端 未结 4 1788
孤街浪徒
孤街浪徒 2020-11-28 04:32

I\'ve used the following C# code to convert a string of JSON data to a dynamic object using the JSON.Net framework:

// Creates a dynamic .Net object represen         


        
4条回答
  •  独厮守ぢ
    2020-11-28 05:27

    XDocument doc = XDocument.Parse(xmlData); //or XDocument.Load(path)
    string jsonText = JsonConvert.SerializeXNode(doc);
    dynamic dyn = JsonConvert.DeserializeObject(jsonText);
    

    I think "cheating" is the answer - the xml solutions are very long :)

提交回复
热议问题