首页 > 解决方案 > 我们如何在 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\": \"horizo​​ntal\",\ 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 \"轴\" : \"horizo​​ntal\",\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}

标签: javascriptjson

解决方案


推荐阅读