You need to sign in to do that
Don't have an account?
Alex.Acosta
JSON and escaped double quote
I'm currently making a callout to a 3rd party vendor and I'm getting a huge response. What is currently messing me up is this section:
"MessageSeq":13,"Description":"config file: config-qa1.txt\"","MessageTS":"2014-02-17T14:46:58","MessageLevel":4,"IsSystemMessage":false
As you can see here, the portion at the end of the Description value is ended with backslash double quote. If I attempt to parse this via the JSONParser I get an exception. Does anyone have an recommendations on how to resolve this?
"MessageSeq":13,"Description":"config file: config-qa1.txt\"","MessageTS":"2014-02-17T14:46:58","MessageLevel":4,"IsSystemMessage":false
As you can see here, the portion at the end of the Description value is ended with backslash double quote. If I attempt to parse this via the JSONParser I get an exception. Does anyone have an recommendations on how to resolve this?
It sounds like your exception is encountered not by the response, but by Apex code mimicking it?
The response format is correct: the backslash \ is correctly placed to permit a " in the JSON.
Check it out, if I put your string, literally, as plaintext into something returnable by an Apex function:
<apex:page contentType="text/plain">{"MessageSeq":13,"Description":"config file: config-qa1.txt\"","MessageTS":"2014-02-17T14:46:58","MessageLevel":4,"IsSystemMessage":false}</apex:page>
And then obtain that string in Apex:
String data = Page.MyTestPage.getContent().toString();
Map<String,Object> obj = (Map<String,Object>)Json.deserializeUntyped(data);
System.debug(obj);
he will deserialize just fine!
But if you intend to recreate that string in Apex source code, say in a test method, as a WebServiceMock or HttpCalloutMock you must escape the backslash itself in Apex:
String data = '{"MessageSeq":13,"Description":"config file: config-qa1.txt\\"","MessageTS":"2014-02-17T14:46:58","MessageLevel":4,"IsSystemMessage":false}';
//see double backslash here_______________________________________________^
See more information in the below thread,
http://salesforce.stackexchange.com/questions/28105/json-and-escaped-double-quote
Regards,
Ashish