You must Sign In to post a response.
  • Category: ASP.NET

    How to create JSON string in C#

    I just used the XmlWriter to create some XML to send back in an HTTP response. How would you create a JSON string. I assume you would just use a stringbuilder to build the JSON string and them format your response as JSON?

    Thanks in Advance
  • #769381
    Hi,
    You can serialize your xml to JSON.

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

    Thanks!
    Anjali Bansal

    ~Give your best and lead the world


  • Sign In to post your comments