-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
303 lines (280 loc) · 11.3 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>JSON-TO-GO</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="HandheldFriendly" content="True" />
<meta name="MobileOptimized" content="320" />
<meta http-equiv="Cache-Control" content="max-age=7200" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="baidu-site-verification" content="mlJsiTNxiD" />
<meta name="google-site-verification" content="CPogK9tQWL5XIDF9F9x_tJyy1HtpDI8Rv6owOEIkUvM" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="all" />
<meta name="keywords" content="json,json在线解析,json格式化,json格式验证,json转xml,xml转json" />
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/base.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
border: 0;
}
#json-src,
#json-target,
#output span {
font-size: 16px;
line-height: 25px;
}
#output, #json-target{
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box;
white-space: pre;
width: 100%;
display: block;
padding: 3%;
font: 14px/1.5em 'Consolas', 'Menlo', 'Monaco', 'Courier New', monospace;
outline: none;
border: none;
resize: vertical;
height: 500px;
height: 65vh;
overflow: scroll;
tab-size: 4;
}
</style>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Favicons -->
</head>
<body style="over-flow:hidden;">
<header class="header">
<div class="row-fluid">
<div class="col-md-5" style="position:relative;">
<a class="logo" href="index.html">Json-To-Go</a>
</div>
<!--<nav class="col-md-7" style="padding:10px 0; " align="right">
<div class="navi">
<a href="index.html" data-placement="bottom">在线解析</a>
<a href="http://lab.json.cn/" data-placement="bottom">JSON实验室</a>
<a href="wiki.html" data-placement="bottom">什么是JSON</a>
<a href="code.html" data-placement="bottom">JSON解析代码</a>
<a href="component.html" data-placement="bottom">JSON组件</a>
</div>
</nav>-->
<br style="clear:both;" />
</div>
</header>
<main class="row-fluid" style="height:85%;min-height:550px;">
<!----------------------json---------------------->
<div class="col-md-4" style="padding:0px;height:100%;">
<div class="tool" style="position:absolute; background-color: #FFFFFF;">
<div style="font-size: 30px; margin: auto; width: 20%; height: 20%; line-height: 20px;">Json</div>
</div>
<textarea id="json-src" class="form-control" style="margin-top: 40px; height:100%;height: 89vh;min-height:520px;padding:10px 30px 10px 30px;border:0;border-right:solid 1px #E5EBEE;border-bottom:solid 1px #eee;border-radius:0;resize: none; outline:none;font-size:16px;"></textarea>
</div>
<!----------------------to----json---------------------->
<div class="col-md-4" style="padding:0;position:relative;height:100%;">
<div class="tool" style="position:absolute;">
<a href="#" class="tip zip" title="压缩" data-placement="bottom"><i class="fa fa-database"></i></a>
<a href="#" class="tip xml" title="转XML" data-placement="bottom"><i class="fa fa-file-excel-o"></i></a>
<a href="#" class="tip shown" title="显示行号" data-placement="bottom"><i class="glyphicon glyphicon-sort-by-order"></i></a>
<a href="#" class="tip clear" title="清空" data-placement="bottom"><i class="fa fa-trash"></i></a>
<a href="#" class="tip save" title="保存" data-placement="bottom"><i class="fa fa-download"></i></a>
<a href="#" class="tip copy" title="复制" data-clipboard-target="#json-target" data-placement="bottom"><i class="fa fa-copy"></i></a>
<a href="#" class="tip compress" title="折叠" data-placement="bottom"><i class="fa fa-compress"></i></a>
</div>
<div id="json-target" class="form-control" style="white-space: pre-line;word-wrap:break-word; margin-top: 40px; height:100%;height: 89vh;min-height:520px;padding:10px 20px 10px 30px;border:0;border-right:solid 1px #E5EBEE;border-bottom:solid 1px #eee;border-radius:0;resize: none; outline:none;font-size:16px;"></div>
<form id="form-save" method="POST"><input type="hidden" value="" id="txt-content" name="content"></form>
</div>
<!----------------------go---------------------->
<div class="col-md-4" style="padding:0px;height:100%;">
<div class="tool" style="position:absolute; background-color: #FFFFFF;">
<a href="#" style="float: left;" class="tip copy" title="复制" data-clipboard-target="#output" data-placement="bottom"><i class="fa fa-copy"></i></a>
<div style="font-size: 30px; margin: auto; width: 20%; height: 20%; line-height: 20px;">Go</div>
</div>
<div id="output" class="form-control" style="margin-top: 40px; height:100%;height: 89vh;min-height:520px;padding:10px 30px 10px 30px;border:0;border-right:solid 1px #E5EBEE;border-bottom:solid 1px #eee;border-radius:0;resize: none; outline:none;font-size:16px;"></div>
</div>
<br style="clear:both;" />
</main>
<link href="css/jquery.numberedtextarea.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
<script src="js/jquery.message.js"></script>
<script src="js/jquery.json.js"></script>
<script src="js/jquery.xml2json.js"></script>
<script src="js/jquery.json2xml.js"></script>
<script src="js/json2.js"></script>
<script src="js/jsonlint.js"></script>
<script src="js/clipboard.min.js"></script>
<script src="js/FileSaver.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.numberedtextarea.js"></script>
<!--<script src="js/jquery.min.js"></script>-->
<script src="js/highlight.min.js"></script>
<script src="js/json-to-go.js"></script>
<script src="js/json-go.js"></script>
<script src="js/gofmt.js" async></script>
<link rel="stylesheet" href="css/tomorrow.highlight.css">
<link rel="stylesheet" href="css/common.css">
<script type="text/javascript">
$('textarea').numberedtextarea();
var current_json = '';
var current_json_str = '';
var xml_flag = false;
var zip_flag = false;
var shown_flag = false;
var compress_flag = false;
$('.tip').tooltip();
function init() {
xml_flag = false;
zip_flag = false;
shown_flag = false;
compress_flag = false;
renderLine();
$('.xml').attr('style', 'color:#999;');
$('.zip').attr('style', 'color:#999;');
}
$('#json-src').keyup(function() {
init();
var content = $.trim($(this).val());
var result = '';
if(content != '') {
//如果是xml,那么转换为json
if(content.substr(0, 1) === '<' && content.substr(-1, 1) === '>') {
try {
var json_obj = $.xml2json(content);
content = JSON.stringify(json_obj);
} catch(e) {
result = '解析错误:<span style="color: #f1592a;font-weight:bold;">' + e.message + '</span>';
current_json_str = result;
$('#json-target').html(result);
return false;
}
}
try {
current_json = jsonlint.parse(content);
current_json_str = JSON.stringify(current_json);
//current_json = JSON.parse(content);
result = new JSONFormat(content, 4).toString();
} catch(e) {
result = '<span style="color: #f1592a;font-weight:bold;">' + e + '</span>';
current_json_str = result;
}
$('#json-target').html(result);
} else {
$('#json-target').html('');
}
});
$('.xml').click(function() {
if(xml_flag) {
$('#json-src').keyup();
} else {
var result = $.json2xml(current_json);
$('#json-target').html('<textarea style="width:100%;position:absolute;height: 80vh;min-height:480px;border:0;resize:none;">' + result + '</textarea>');
xml_flag = true;
$(this).attr('style', 'color:#15b374;');
}
});
$('.shown').click(function() {
if(!shown_flag) {
renderLine();
$('#line-num').show();
$('.numberedtextarea-line-numbers').show();
shown_flag = true;
$(this).attr('style', 'color:#15b374;');
} else {
$('#line-num').hide();
$('.numberedtextarea-line-numbers').hide();
shown_flag = false;
$(this).attr('style', 'color:#999;');
}
});
function renderLine() {
var line_num = $('#json-target').height() / 20;
$('#line-num').html("");
var line_num_html = "";
for(var i = 1; i < line_num + 1; i++) {
line_num_html += "<div>" + i + "<div>";
}
$('#line-num').html(line_num_html);
}
$('.zip').click(function() {
if(zip_flag) {
$('#json-src').keyup();
} else {
$('#json-target').html(current_json_str);
zip_flag = true;
$(this).attr('style', 'color:#15b374;');
}
});
$('.compress').click(function() {
if(!compress_flag) {
$(this).attr('style', 'color:#15b374;');
//$(this).attr('title','取消折叠').tooltip('fixTitle').tooltip('show');
$($(".fa-minus-square-o").toArray().reverse()).click();
compress_flag = true;
} else {
while($(".fa-plus-square-o").length > 0) {
$(".fa-plus-square-o").click();
}
compress_flag = false;
$(this).attr('style', 'color:#555;');
$(this).attr('title', '折叠').tooltip('fixTitle').tooltip('show');
}
});
$('.clear').click(function() {
$('#json-src').val('');
$('#json-target').html('');
});
(function($) {
$.fn.innerText = function(msg) {
if(msg) {
if(document.body.innerText) {
for(var i in this) {
this[i].innerText = msg;
}
} else {
for(var i in this) {
this[i].innerHTML.replace(/&lt;br&gt;/gi, "n").replace(/(&lt;([^&gt;]+)&gt;)/gi, "");
}
}
return this;
} else {
if(document.body.innerText) {
return this[0].innerText;
} else {
return this[0].innerHTML.replace(/&lt;br&gt;/gi, "n").replace(/(&lt;([^&gt;]+)&gt;)/gi, "");
}
}
};
})(jQuery);
$('.save').click(function() {
// var content = JSON.stringify(current_json);
// $('#txt-content').val(content);
//var text = "hell world";
var html = $('#json-target').html().replace(/\n/g, '<br/>').replace(/\n/g, '<br>');
var text = $('#json-target').innerText().replace(' ', ' ');
var blob = new Blob([text], {
type: "application/json;charset=utf-8"
});
var timestamp = new Date().getTime();
saveAs(blob, "format." + timestamp + ".json");
});
$('.copy').click(function() {
//$.msg("成功复制到粘贴板","color:#00D69C;");
// $(this).tooltip('toggle')
// .attr('data-original-title', "复制成功!")
// .tooltip('fixTitle')
// .tooltip('toggle');
});
var clipboard = new Clipboard('.copy');
$('#json-src').keyup();
</script>
</body>
</html>