2013-01-06 05:19:38 +08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
|
|
|
<script type="text/javascript" src="../jsoneditor.js"></script>
|
2013-01-06 19:58:09 +08:00
|
|
|
<style type="text/css">
|
|
|
|
#jsoneditor {
|
|
|
|
width: 500px;
|
|
|
|
height: 500px;
|
|
|
|
}
|
|
|
|
</style>
|
2013-01-06 05:19:38 +08:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p>
|
|
|
|
<button id="setJSON">Set JSON</button>
|
|
|
|
<button id="getJSON">Get JSON</button>
|
|
|
|
</p>
|
2013-01-06 19:58:09 +08:00
|
|
|
<div id="jsoneditor"></div>
|
2013-01-06 05:19:38 +08:00
|
|
|
|
|
|
|
<script type="text/javascript" >
|
|
|
|
// create the editor
|
2013-08-28 04:50:20 +08:00
|
|
|
var container = document.getElementById('jsoneditor');
|
2013-01-06 19:58:09 +08:00
|
|
|
var editor = new jsoneditor.JSONEditor(container);
|
2013-01-06 05:19:38 +08:00
|
|
|
|
|
|
|
// set json
|
2013-08-28 04:50:20 +08:00
|
|
|
document.getElementById('setJSON').onclick = function () {
|
2013-01-06 05:19:38 +08:00
|
|
|
var json = {
|
2013-08-28 04:50:20 +08:00
|
|
|
'array': [1, 2, 3],
|
|
|
|
'boolean': true,
|
|
|
|
'null': null,
|
|
|
|
'number': 123,
|
|
|
|
'object': {'a': 'b', 'c': 'd'},
|
|
|
|
'string': 'Hello World'
|
2013-01-06 05:19:38 +08:00
|
|
|
};
|
|
|
|
editor.set(json);
|
|
|
|
};
|
|
|
|
|
|
|
|
// get json
|
2013-08-28 04:50:20 +08:00
|
|
|
document.getElementById('getJSON').onclick = function () {
|
2013-01-06 05:19:38 +08:00
|
|
|
var json = editor.get();
|
|
|
|
alert(JSON.stringify(json, null, 2));
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|