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
eswarieswari 

URGENT: Get the response data as json format

Hi,

 

I am making a REST Service call from my apex class which returns the data in xml format.

 

I want the data to be in json format instead of xml.

 

Is there any way to get the data as json by specifying any property or something?

 

 

 

Navatar_DbSupNavatar_DbSup

Hi,

 

Instead of using the format parameter, you can also specify the returned format in an accept-request header using as below

 

req.setHeader('Accept', 'application/json;charset=UTF-8');  // When you use setMethod as 'GET' To get response in xml format.

req.setHeader('Content-Type', 'text/json;charset=UTF-8');  // When you use setMethod as 'POST'     To get response in xml format.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.