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.

Share:
10,554
Boris Bachovski
Author by

Boris Bachovski

Updated on July 29, 2022

Comments

  • Boris Bachovski
    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 as replace('\\"', '"'); but didn't work.

    Any help is appreciated.