REST API - 转义字符

问题描述 投票:0回答:1

假设我有一个注释字段,其中包含换行符。 什么解决方案是正确的,它们之间有什么区别?

1

{
"notes" : "test test test \n line2"
}

2

{
"notes" : "test test test \\n line2"
}

谢谢你

rest escaping ascii mysql-real-escape-string
1个回答
0
投票

在下面的输出中:

{
 "notes" : "test test test \n line2"
}

已使用

\n
转义新行字符。

在你的用户界面上,你可能想显示

test test test 
line2

我假设您正在从数据存储(可能是 MySQL)检索 json。如果是,请参阅有关在 MYSSQL 中转义换行符的答案MySQL 字符串文字

© www.soinside.com 2019 - 2024. All rights reserved.