json writer adding extra slash to the serialized file

1.2k views Asked by At

In JSONObject I have put {"text":"\folder1\folder2\filename.txt"}.

It is serialized as {"text":"\\folder1\\folder2\\filename.txt"} instead of {"text":"\folder1\folder2\filename.txt"}.

Why is it adding extra forward slash?

1

There are 1 answers

0
Ragu On

Therefore the \ must be escaped for the JSON to be valid.according JSON spec. your parser will also remove the second \ when reading the JSON.

read this JSON spec.read this answer