1
{"name": "monkey","age": "24","height": 164.0}
如果想讓以上json字符串在頁面上展示的比較易讀,即變成下面的style:
1
{
2
"name": "monkey",
3
"age": "24",
4
"height": 164.0cm
5
}
本文介紹的方法基于javascript ,代碼如下:
01
<html>
02
<head>/
03
//style中是css代碼
04
<style type="text/css">
05
body
06
{
07
white-space: pre;
08
font-family: monospace;
09
}
10
</style>
11
//script中是javascript代碼
12
<script>
13
window.error_id_msgs = <%= error_id_msgs | raw %>;
14
function myFunction() {
15
document.body.innerHTML = "";
16
document.body.appendChild(document.createTextNode(JSON.stringify(window.error_id_msgs, null, 4)));
17
}
18
</script>
19
</head>
20
<body onload="myFunction()"> //表示頁面加載時(shí)調(diào)用myFunction()
21
</body>
22
</html>
其中window.error_id_msgs是所要轉(zhuǎn)換的json對(duì)象,css和myFunction結(jié)合可實(shí)現(xiàn)頁面展示轉(zhuǎn)換
更多信息請(qǐng)查看IT技術(shù)專欄