Json object contains new string character converted to "\ n" when converting json object to string or byte

A Json object containing a new string character is converted to "\n"

when converting a json object to a string or byte. If I choose any of the methods below it converts the new string character to \n

.

byte[] json = objectMapper.writeValueAsBytes(jsonObject);
 String json = objectMapper.writeValueAsString(jsonObject);
 objectMapper.writeValue(json, jsonElection);

      

Example:

Brown 
And
Ken

      

The above data has been changed as

Brown\nAnd\nKen

      

Please help solve this problem.

+3


source to share


1 answer


This is the intended work. Newlines are escaped with a character sequence "\n"

.

Your output is fine, which means three words "Brown"

, "And"

and "Ken"

separated by newlines. When you decode it, you will have the same text (as your input).



You asked for json text and this is what you got. If the json value contains a newline character, it is represented as a character sequence "\n"

.

+5


source







All Articles