Json对象包含换行符,该换行符转换为"\ n".在将json对象转换为字符串或字节时 [英] Json object contains new line character converted to "\n" while converting json object to string or byte

查看:829
本文介绍了Json对象包含换行符,该换行符转换为"\ n".在将json对象转换为字符串或字节时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Json对象在将json对象转换为字符串或字节时被转换为"\n".如果我选择以下任一方式,它会将换行符转换为\n.

Json object containing new line character gets converted to "\n" while converting json object to string or byte. If I choose any one of the below way it is converting new line character to \n.

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

示例:

Brown 
And
Ken

以上数据已更改为

Brown\nAnd\nKen

帮我解决这个问题.

推荐答案

这是预期的工作方式.换行符转义为"\n"字符序列.

That is the intended working. Newline characters are escaped to the "\n" character sequence.

您的输出非常好,它表示由换行符分隔的3个单词"Brown""And""Ken".解码时,您将获得与输入内容完全相同的文本.

Your output is perfectly fine and it means the 3 words "Brown", "And" and "Ken" separated by newline characters. When you decode it you will have the exact same text (as your input).

您要求输入json文本,这就是您所得到的.如果json值包含换行符,则由字符序列"\n"表示.

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

这篇关于Json对象包含换行符,该换行符转换为"\ n".在将json对象转换为字符串或字节时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆