【发布时间】:2016-02-23 08:20:35
【问题描述】:
我尝试使用以下格式将 JSON 插入到 Outlook/电子邮件客户端的正文中
location.href = "mailto:" + "email@domain.com" + "?subject=" + "Notes" + "&body=" + JSON.stringify(data, null, 4);
给4个空格JSON.stringify(data, null, 4)
[
{
"page": "article_0_page_0",
"note": "Note 1"
},
{
"page": "article_0_page_1",
"note": "Note 2"
}
]
我想输出为
<b>article_0_page_0</b>\n\r
Note 1
<b>article_0_page_1</b>\n\r
Note 2
请提供任何正则表达式解决方案。
编辑:我的尝试
var str = "";
for(var i=0; i<data.length; i++) {
str += "<strong>" + data[i].page + "</strong><br>" + data[i].note + "<br><br>";
}
【问题讨论】:
-
您能描述一下您的尝试吗?
-
您能告诉我们您到目前为止所做的事情吗?
-
@k0pernikus 你用了 11 秒 :)
-
@Oleander 本来会更快,但出于某种原因“你尝试了什么?”是不允许的评论内容;)
-
@user2727195 为什么不根据您的规格进行更改?你快完成了。
标签: javascript json regex pretty-print