function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ashok  45ashok 45 

How to Convert(Serialize) XML into JSON format?





Hi All,
    This is my sample XML data. I want to convert(Serialize) XML into JSON. Iam doing like this If am wrong please let me know.
   
    
    
 String xml= ' <?xml version="1.0" encoding="utf-16"?>
 
 <GETmethod xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Extend />
  <Successful>true</Successful>
  <CustAllowed>
    <CustomerAllow>
      <SampleData />
      <CurrentDate>10/14/2015</currentDate>
      <DocID>296</DocID>
      <DType>BP</CIDType>
    </CustAllow>
  </CustAllowed>
 </GetMethod>';
 
 
 String JSONString = JSON.serialize(xml);
 
    I want to post it into future method, like below. will it take as JSON format or String format?
    
 ==> CalloutMethod(JSONString)
 
  @future(callout=true)
  public static void CalloutMethod(JSONString)
  {
   //Code 
  }
pconpcon
You cannot just use the serialize method on your XML.  You will need to convert the XML to an object by parsing it [1] and then serializing the created object.

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_xml_dom.htm