JSON Strings and Escape Character Handling Methods

I am using the official JSON library for my java project project, I noticed something strange.

If I have json, for example:

{
  "text": "This is a multiline\n text"
}

And I'm trying to get a string like this:

System.out.println(jsonObject.getString("text"));

I get this in the output:

This is a multiline\n text

Instead:

This is a multiline
text

Does anyone know the correct way to handle special characters like \ n and \ t? I could always replace each, but I would have to process everything one at a time.

+5
source share
2 answers

, " " \n ( \n ), \n ( \n ). , , , , .

: json_obj.text.replace(/\\n/g,"\n");, .

+1

, :

{
  "text": "This is a multiline\\n text"
}
+4

All Articles