微信搜索我吃你家米了关注公众号
今天给大家介绍一款json编辑器https://github.com/josdejong/jsoneditor
JSON Editor是一款基于web的json编辑与查看工具
首先来看一下如何安装这款工具
解压后进入jsoneditor目录
执行npm install
然后执行npm run build
执行完上述操作后,我们编写如下html文件:
<!DOCTYPE HTML>
<html>
<head>
<!-- when using the mode "code", it's important to specify charset utf-8 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link href="jsoneditor.min.css" rel="stylesheet" type="text/css">
<script src="jsoneditor.min.js"></script>
</head>
<body>
<div id="jsoneditor" style="width: 400px; height: 400px;"></div>
<script>
// create the editor
const container = document.getElementById("jsoneditor")
const options = {}
const editor = new JSONEditor(container, options)
// set json
const initialJson = {
"Array": [1, 2, 3],
"Boolean": true,
"Null": null,
"Number": 123,
"Object": {"a": "b", "c": "d"},
"String": "Hello World"
}
editor.set(initialJson)
// get json
const updatedJson = editor.get()
</script>
</body>
</html>
然后在浏览器中打开上面的html文件即可