json作为ajax常用的一种数据类型,经常使用。但如果字段中出现换行符如何处理?

第一种解决方案:

后台代码把换行符\r\n替换为\\r\\n,前台代码js收到的字符就是\r\n,这时前端就可以根据\r\n做判断,替换为换行标签(br)

第二种方案:

后台代码对换行未做任何处理,直接给前端,这时前端就要这么处理了:

JSON.parse(JSON.stringify(s).replace(/\\n|\\r/g, "<br/>"))
<p v-html="regx(item.fieldOrignText)"></p>

第三种方案:

<pre>{{data}}</pre>

直接用pre标签展示内容,这时需要对比展示布局是否是需要的布局

仅供参考。。。。。。。

GitHub 加速计划 / js / json
50
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 天前 )
dff2b475 Adds pre-multiplication overflow detection to catch cases where dimension products would exceed size_t max. The previous check only detected when overflow resulted in exactly 0 or SIZE_MAX, missing other cases. Retains the original post-multiplication check for backward compatibility. Adds tests verifying overflow detection with dimensions (2^32+1)×(2^32), which previously overflowed silently to 2^32. This prevents custom SAX handlers from receiving incorrect array sizes that could lead to buffer overflows. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi> 15 小时前
eef76c20 * :white_check_mark: add test for C++20 modules Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :rotating_light: fix warning Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Add missing header (#4763) * :bug: add missing header Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :rotating_light: fix warning Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :rotating_light: fix warning Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> 1 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐