2013-01-06 05:19:38 +08:00
|
|
|
<!DOCTYPE HTML>
|
2020-09-23 16:23:38 +08:00
|
|
|
<html lang="en">
|
2013-01-06 05:19:38 +08:00
|
|
|
<head>
|
2020-09-23 16:23:38 +08:00
|
|
|
<meta charset="utf-8">
|
|
|
|
|
2014-05-30 04:13:37 +08:00
|
|
|
<title>JSONEditor | Basic usage</title>
|
2015-02-28 04:54:04 +08:00
|
|
|
|
2015-03-01 03:47:23 +08:00
|
|
|
<link href="../dist/jsoneditor.css" rel="stylesheet" type="text/css">
|
|
|
|
<script src="../dist/jsoneditor.js"></script>
|
2015-02-28 04:54:04 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
<style type="text/css">
|
|
|
|
#jsoneditor {
|
|
|
|
width: 500px;
|
|
|
|
height: 500px;
|
|
|
|
}
|
|
|
|
</style>
|
2013-01-06 05:19:38 +08:00
|
|
|
</head>
|
|
|
|
<body>
|
2013-11-16 01:11:50 +08:00
|
|
|
<p>
|
|
|
|
<button id="setJSON">Set JSON</button>
|
|
|
|
<button id="getJSON">Get JSON</button>
|
|
|
|
</p>
|
|
|
|
<div id="jsoneditor"></div>
|
2013-01-06 05:19:38 +08:00
|
|
|
|
2015-02-28 04:54:04 +08:00
|
|
|
<script>
|
2013-11-16 01:11:50 +08:00
|
|
|
// create the editor
|
2019-08-29 21:45:32 +08:00
|
|
|
const container = document.getElementById('jsoneditor')
|
|
|
|
const options = {}
|
|
|
|
const editor = new JSONEditor(container, options)
|
2013-01-06 05:19:38 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
// set json
|
|
|
|
document.getElementById('setJSON').onclick = function () {
|
2019-08-29 21:45:32 +08:00
|
|
|
const json = {
|
2013-11-16 01:11:50 +08:00
|
|
|
'array': [1, 2, 3],
|
|
|
|
'boolean': true,
|
2018-08-22 18:10:15 +08:00
|
|
|
'color': '#82b92c',
|
2013-11-16 01:11:50 +08:00
|
|
|
'null': null,
|
|
|
|
'number': 123,
|
|
|
|
'object': {'a': 'b', 'c': 'd'},
|
2019-12-11 18:34:24 +08:00
|
|
|
'time': 1575599819000,
|
2020-09-23 16:06:12 +08:00
|
|
|
'string': 'Hello World',
|
|
|
|
'onlineDemo': 'https://jsoneditoronline.org/'
|
2019-08-29 21:45:32 +08:00
|
|
|
}
|
|
|
|
editor.set(json)
|
|
|
|
}
|
2013-01-06 05:19:38 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
// get json
|
|
|
|
document.getElementById('getJSON').onclick = function () {
|
2019-08-29 21:45:32 +08:00
|
|
|
const json = editor.get()
|
|
|
|
alert(JSON.stringify(json, null, 2))
|
|
|
|
}
|
2013-11-16 01:11:50 +08:00
|
|
|
</script>
|
2013-01-06 05:19:38 +08:00
|
|
|
</body>
|
|
|
|
</html>
|