+ Start a Discussion
S SaiS Sai 

how to parse Json Format

hi 

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
    <GetCitiesByCountryResult>
    <NewDataSet>
            <Table>
        <Country>India</Country>
        <City>Bangalore</City>
      </Table>
    </NewDataSet>
    </GetCitiesByCountryResult>
    </GetCitiesByCountryResponse>
</soap:Body>
</soap:Envelope>

Thanks 
Sai
Amit Chaudhary 8Amit Chaudhary 8
Please try below XML to JSON converter
1) http://www.utilities-online.info/xmltojson/#.VyBUffl97Dc

JSON
{
  "soap:Envelope": {
    "-xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
    "-xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
    "-xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
    "soap:Body": {
      "GetCitiesByCountryResponse": {
        "-xmlns": "http://www.webserviceX.NET",
        "GetCitiesByCountryResult": {
          "NewDataSet": {
            "Table": {
              "Country": "India",
              "City": "Bangalore"
            }
          }
        }
      }
    }
  }
}
Let us know if this will help you

Thanks
Amit Chaudhary
 
S SaiS Sai
Hi Amit,

Thanks for your reply 

public class CityFinder {
    public static void FindCity(string Country){
    
        httpRequest req = new httpRequest();
        string endpoint='http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName='+Country;
        req.setEndpoint(endpoint);
        req.setMethod('GET');   
        req.setHeader('Accept', 'application/json;charset=UTF-8');
          req.setTimeout(20000);
          //req.setHeader('Content-Type', 'text/xml; charset=utf-8');
        req.setHeader('SOAPAction','http://www.webserviceX.NET/GetCitiesByCountry');
        system.debug('Req ########'+req);
        
        Http http = new Http(); 
        HTTPResponse res = http.send(req);
    
        string bodyRes = res.getBody();
    
        string r1 = bodyRes.replace('&lt;','<');
        string r2 = r1.replace('&gt;','>');
        system.debug('RESPONSE>>>>'+r2); 
     
      

}
}

 Here I am getting output 
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
    <GetCitiesByCountryResult>
    <NewDataSet>
            <Table>
        <Country>India</Country>
        <City>Bangalore</City>
      </Table>
    </NewDataSet>
    </GetCitiesByCountryResult>
    </GetCitiesByCountryResponse>
</soap:Body>
</soap:Envelope>

i want to display output is json format