javascript - 我们如何在 javascript 中将“\n”添加到字符串化 JSON
问题描述
我想在每个换行符上添加 '\n' 。可以用reg表达式实现吗
{
"name": " ",
"type": "column",
"axis": "vertical",
"content_type": "stack_view",
"contents": [
{
"name": "",
"type": "row",
"axis": "horizontal",
"content_type": "field",
"contents": [],
"isParentBlock": false,
"weight": 100
}
],
"isParentBlock": true,
"weight": 100
}
PS-我想实现如下所示。
{\r\n \"name\": \"FormStack\",\r\n \"type\": \"row\",\r\n \"axis\": \"horizontal\",\ r\n \"content_type\": \"stack_view\",\r\n \"contents\": [\r\n {\r\n \"name\": \" \",\r\n \"type\": \"column\",\r\n \"axis\": \"vertical\",\r\n \"content_type\": \"stack_view\",\r\n \"内容\": [\r\n {\r\n \"名称\": \"\",\r\n \"类型\": \"行\",\r\n \"轴\" : \"horizontal\",\r\n \"content_type\": \"field\",\r\n \"contents\": [\r\n [\r\n {\r\n \"标题\”: \”签名\",\r\n \"值\": \"\",\r\n \"可选\": \"\",\r\n \"类型\": \"signature_stack\", \r\n \"标识符\": \"\",\r\n \"值\": [],\r\n \"属性\": {\r\n \"强制\": \ "\",\r\n \"规则\": \"\"\r\n },\r\n \"按钮\": [],\r\n \"重量\": 50,\ r\n \"wrap\": false,\r\n \"$$hashKey\": \"object:137\"\r\n }\r\n ],\r\n [\r\n {\r\n \"title\": \"输入标题\",\r\n \"value\": \"\",\r\n \"可选\": \"\",\r\n \"type\": \"text_view\",\r\n \"标识符\": \"\",\r\n \"值\": [],\r\n \"属性\": {\r\n \"强制\": \"\", \r\n \"规则\": \"\"\r\n },\r\n \"按钮\": [],\r\n \"重量\": 50,\r\n \ "wrap\": false,\r\n \"$$hashKey\": \"object:151\"\r\n }\r\n ]\r\n ],\r\n \"isParentBlock\ ": false,\r\n \"权重\": 50\r\n },\r\n {\r\n \"名称\": \"\",\r\n \"类型\": \"行\",\r\n \"轴\": \"水平\ ",\r\n \"content_type\": \"field\",\r\n \"contents\": [],\r\n \"isParentBlock\": false,\r\n \"权重\": 50\r\n }\r\n ],\r\n \"isParentBlock\": true,\r\n \"weight\": 100\r\n }\r\n ],\ r\n \"isParentBlock\": true,\r\n \"weight\": 100\r\n}\r\n \"weight\": 50\r\n }\r\n ],\r\n \"isParentBlock\": true,\r\n \"weight\": 100\r\n } \r\n ],\r\n \"isParentBlock\": true,\r\n \"weight\": 100\r\n}\r\n \"weight\": 50\r\n }\r\n ],\r\n \"isParentBlock\": true,\r\n \"weight\": 100\r\n } \r\n ],\r\n \"isParentBlock\": true,\r\n \"weight\": 100\r\n}
解决方案
推荐阅读
- python - 从文本python 3中提取特定模式
- vue.js - 多个内联输入值,使用 Vue 渲染函数
- sql-server - 将行转换为列
- corda - 分析 Corda 应用程序
- ios - UITableView 滚动后单元格 UIProgressView 不更新
- batch-file - (Batch) 如何将 `@Echo Off` 函数从一个 .bat 文件发送到另一个
- regression - 滚动回归和多重共线性
- regex - Web 服务响应中多行的正则表达式
- javascript - 用另一个更新选择列表 - Vue.js
- android - 查找时间是否在具有时区约束的时间范围内