How to convert XML to JSON using C#/LINQ?

前端 未结 3 1128
感情败类
感情败类 2020-11-30 01:52

I have the following XML file that I need to convert to JSON in the server. Initially I thought I would convert it to a Dictionary and then use the JavaScriptSerializer to t

3条回答
  •  执笔经年
    2020-11-30 02:30

    Is it necessary to use LINQ? Otherwise you can try this:

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

    Taken from this post.

提交回复
热议问题