-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_format_offline.html
68 lines (65 loc) · 2.08 KB
/
json_format_offline.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
@media screen {
}
</style>
<script type="text/javascript">
let index = 0
function stringify_1 () {
console.log('stringify_1')
const input = document.getElementById('input')
try {
const j = JSON.parse(input.value)
console.log(j)
input.value = JSON.stringify(j)
// document.getElementById('input').setAttribute('value', JSON.stringify(j));
index += 1
document.getElementById('info').innerText = `${index} 格式化成功`
} catch (e) {
console.log(e)
index += 1
document.getElementById('info').innerText = `${index} 格式化失败:${e}`
}
}
function stringify_s4 () {
console.log('stringify_1')
const input = document.getElementById('input')
try {
const j = JSON.parse(input.value)
console.log(j)
input.value = JSON.stringify(j, null, 4)
// document.getElementById('input').setAttribute('value', JSON.stringify(j));
index += 1
document.getElementById('info').innerText = `${index} 格式化成功`
} catch (e) {
console.log(e)
index += 1
document.getElementById('info').innerText = `${index} 格式化失败:${e}`
}
}
</script>
</head>
<body>
<div>
<span style="font-weight: bold">JSON格式化  by  JimmytheMouth</span>
</div>
<div>
<span>说明:在输入框中输入json,点击下面的2个按钮进行格式化,格式化成功或失败的信息会展示在“信息显示”中</span>
</div>
<div>
<button onclick="stringify_1()">一行</button>
<button onclick="stringify_s4()">4空格</button>
</div>
<div>
<span id="info">信息显示</span>
</div>
<textarea id="input" style="width: 90vw;height: 30vw;text-align: start"></textarea>
</body>
</html>