jsoneditor/demo.html

44 lines
1.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor.css">
<script type="text/javascript" src="jsoneditor/jsoneditor.js"></script>
<style type="text/css">
body {font: 11pt sans-serif;}
</style>
</head>
<body>
<p>
<button onclick="setJSON();">Set JSON</button>
<button onclick="getJSON();">Get JSON</button>
</p>
<div id="jsoneditor" style="width: 500px; height: 400px;"></div>
<script type="text/javascript" >
// create the editor. Optionally, parameters json and options can be
// specified in the constructor.
var container = document.getElementById("jsoneditor");
var editor = new JSONEditor(container);
// set json
function setJSON () {
var json = {
"array": [1, 2, 3],
"boolean": true,
"null": null,
"number": 123,
"object": {"a": "b", "c": "d"},
"string": "Hello World"
};
editor.set(json);
}
// get json
function getJSON() {
var json = editor.get();
alert(JSON.stringify(json, null, 2));
}
</script>
</body>
</html>