APEX JSON Generator writeString escapes quotes
10,554
Solved it. Had to do the following:
String genString = gen.getAsString();
genString = genString.replace('\\"', '"');
genString = genString.replace('"{', '{');
genString = genString.replace('}"', '}');
Replacing on the fly didn't work for some reason.
Author by
Boris Bachovski
Updated on July 29, 2022Comments
-
Boris Bachovski almost 2 years
Is there a way NOT to escape the quotes in a string when using JSON Generator's method
writeString
? I'm getting the following result:"{\"Name\":\"asdsads\",\"Query\":\"adasdasd\"},{\"Name\":\"12312312\",\"Query\":\"3123123\"},{\"Name\":\"d23d2\",\"Query\":\"3d23d2\"}"
instead of:
{"Name":"asdsads","Query":"adasdasd"},{"Name":"12312312","Query":"3123123"},{"Name":"d23d2","Query":"3d23d2"}
I have tried
replace('\\', '');
as well asreplace('\\"', '"');
but didn't work.Any help is appreciated.