+ Start a Discussion
Diwakar G 7Diwakar G 7 

Passing Json to call post method

Hi,
Please help me in creating body using Apex. I need to pass the body in post method.
[
    { "n": "MyApexClass", "r": false,  "t": "ApexClass" },
    { "n": "SysAdmin", "r": false, "t": "Profile" },
    { "n": "Account", "r": true, "t": "CustomObject" }
 ]

Thanks and Regards,
Diwakar G
Raj VakatiRaj Vakati
Refer this code
 
// Sening the http body with JSON 
String jsonData ='[{ "n": "MyApexClass", "r": false,  "t": "ApexClass" },{ "n": "SysAdmin", "r": false, "t": "Profile" },{ "n": "Account", "r": true, "t": "CustomObject" }]' ; 
String endpoint = 'http://www.example.com/service';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setbody(jsonData);
Http http = new Http();
HTTPResponse response = http.send(req);