json转string换行java,Json对象包含换行符,转换为"\ n"在将json对象转换为字符串或字节时...

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);

Example:

Brown

And

Ken

Above data got changed as

Brown\nAnd\nKen

Help me to solve this issue.

解决方案

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

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).

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".

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值