convert xml to json format

Below codes response to xml format when jquery is called.
1. How can I code response to Json format?
2. More importantly, how to consume it?

#region GetNetPrice
        [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "ProQuoteService/GetNetPrice({CompanyID},{CustomerNo},{Model},{Qty},{OrderDate},{RepNo})")]
        String GetNetPrice(string CompanyID, string CustomerNo, string Model, string Qty, string OrderDate, string RepNo);

   public string GetNetPrice(string CompanyID, string CustomerNo, string Model, string Qty, string OrderDate, string RepNo)
            Qty = Qty.Replace("^", ",");
            Model = Model.Replace("^", ",");

            OrderDate = "11/07/2014";
	    #region modelList
            if (Model.StartsWith("["))
                Model = Model.Substring(1);

            if (Model.EndsWith("]"))
                Model = Model.Substring(0, Model.Length - 1);
            #region qtyList
            if (Qty.StartsWith("["))
                Qty = Qty.Substring(1);

            if (Qty.EndsWith("]"))
                Qty=Qty.Substring(0, Qty.Length - 1);
            #region procedures
            string body = string.Format(@"<SOAP:Envelope><SOAP:Header></SOAP:Header>
            </SOAP:Envelope>", CompanyID, CustomerNo, Model, Qty, OrderDate, RepNo);

                Usa.B2B.ERP.jBase.Helper.Retrieve d = new Usa.B2B.ERP.jBase.Helper.Retrieve(body);
                XmlDocument xml = new XmlDocument();
                string node =  xml.SelectSingleNode("//RetrieveResult").InnerXml.Replace(@"\","");                                  
	        string status = xml.SelectSingleNode("//Status").InnerXml;
                string orderDate = xml.SelectSingleNode("//OrderDate").InnerXml;
                string customerNumber = xml.SelectSingleNode("//CustomerNumber").InnerXml;
                string model = xml.SelectSingleNode("//Model").InnerXml;
                string orderDetailList = xml.SelectSingleNode("//OrderDetail").InnerXml;
                return node;
            catch (Exception ex)
                //ILog log = LogManager.GetLogger("");
                //log.Error(m => m("Error:", ex.ToString()));
                throw ex;

Open in new window

Who is Participating?
Ronak PatelCommented:
Hi ITsolutionWizard,

You can use JsonConvert.SerializeXmlNode() method to convert xml string to Json string.
Please refer below code. I think it will solve your purpose.

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

Open in new window

Reference Link: Converting between JSON and XML

You can get the required assemblies from here: Newtonsoft.Json

Hope this helps.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.