You need to sign in to do that
Don't have an account?
Getting a JSON string to parse with Apex
I am trying to receive a JSON string in salesforce by converting a blob in the body of an Http request. However, when I convert the blob to a string, \ characters get inserted before the quotation marks, which prevents me from parsing.
I tried to take the string and remove all \ characters by using the string.removeAll() method... but that didn't work either.
RestRequest req =RestContext.request;
Blob jsonBlob = req.requestBody;
String jsonString = jsonBlob.toString();
return jsonString;
The original string (the one that is received as a blob) looks like this:
{"putTimeCard":{"timecard":{"timeCardID":"","employeeID":""}}
And after converting to a salesforce string and assigned to the jsonString is altered to:
{\"putTimeCard\":{\"timecard\":{\"timeCardID\": \"\",\"employeeID\": \"\"}}
Has anyone found a solution for this? Thanks
Just use the resp.getBody(). no need to convert it to a blob..
Or String s = resp.getBody();
As far as your replacing how are you doing it?
it should be:
jsonString = jsonString.replace('\\');