How to remove the escape characters"" from the Response and the the double quotes at the beginning and the end from the Response ? please check the expected valid response in the below. Code :
@HttpPost
global static string dopost() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
Case tkt= (Case)JSON.deserialize(req.requestBody.toString(),Case.class);
system.debug(tkt);
try {
insert tkt;
}
catch(DmlException e) {
return 'The following exception has occurred: ' + e.getMessage();
}
Case insertedCase = [Select Id,CaseNumber,Subject,Status,Reason,Origin from Case Where Id =:tkt.Id];
return JSON.serialize(insertedCase);
}
Response :
"{"attributes":{"type":"Case","url":"/services/data/v37.0/sobjects/Case/5002800000SzkMOAAZ"},"Id":"5002800000SzkMOAAZ","CaseNumber":"00001081","Subject":"TWX-Request","Status":"New","Reason":"Deviation","Origin":"TWX"}"
Valid Response to parse :
{"attributes":{"type":"Case","url":"/services/data/v37.0/sobjects/Case/5002800000SzkMOAAZ"},"Id":"5002800000SzkMOAAZ","CaseNumber":"00001081","Subject":"TWX-Request","Status":"New","Reason":"Deviation","Origin":"TWX"}