缘由:需要将参数(json)展示在html中,查看.
出现问题:json挤到一起没有格式。使用JSON.stringify,并配置缩进。这两个不可少。然后使用
<pre>
三者必须配合。
HTML:
<pre>
<code id="show"></code>
</pre>
JS:
var show = document.getElementById('show'),
newData = JSON.stringify(arr, null, 4);
show.innerHTML = newData;
结果:
arr = [{
id: 1,
desc: "This is the description of the first object."
}, {
id: 2,
desc: "This is the description of the second object."
}, {
id: 3,
desc: "This is the description of the third object. Now, I'm going to repeat the description of this value.This is the description of the third objectThis is the description of the third objectThis is the description of the third object"
}, {
id: 4,
desc: "This is the description of the third object."
}]
参考:
https://www.jianshu.com/p/db8d77b3de9a