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
        [OperationContract]
        [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);
        #endregion

   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);
            }
            #endregion
            #region procedures
            try
            {
            string body = string.Format(@"<SOAP:Envelope><SOAP:Header></SOAP:Header>
            <SOAP:Body>
            <m:Retrieve>
            <itemid>
            <GenerateReportRequest><ReportType>CUST-NETPRICE</ReportType><ReportFormat>XML</ReportFormat>
            <ReportParams><CompanyNumber>{0}</CompanyNumber><CustomerNumber>{1}</CustomerNumber><Model>{2}</Model>
            <Quantity>{3}</Quantity><OrderDate>{4}</OrderDate><RepNumber>{5}</RepNumber><Delimiter>,</Delimiter>
            </ReportParams>
            </GenerateReportRequest>
            </itemid>
            </m:Retrieve>
            </SOAP:Body>
            </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();
                xml.LoadXml(d.GetData());                
                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;
            }
            #endregion
        }

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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();
doc.LoadXml(node);
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.

Regards,
Ronak
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.