JSON在线编辑器插件jsoneditor的用法,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
jsoneditor一个在浏览器上预览、编辑、格式化和验证jsON的工具。可以作为Commonjs模块、AMD模块或者常规JavaScript文件加载。
在线json支持的浏览器
支持的浏览器:Chrome,Firefox,Safari,Opera,IE9+。
在线json用法
在学习实现json编辑器组件之前,我们有必要了解一下jsoneditor这个第三方组件的用法与api.1.jsoneditor的使用我们先执行npminstall安装我们的组件npminstalljsoneditor
其次手动引入样式文件<linkhref="jsoneditor/dist/jsoneditor.min.css"rel="stylesheet"type="text/css">
这样,我们就能使用它的api了:<divid="jsoneditor"></div><script>//创建编辑器varcontainer=document.getElementById("jsoneditor");vareditor=newJSONEditor(container);//设置json数据functionsetJSON(){varjson={"Array":[1,2,3],"Boolean":true,"Null":null,"Number":123,"Object":{"a":"b","c":"d"},"String":"HelloWorld"};editor.set(json);}//获取json数据functiongetJSON(){varjson=editor.get();alert(JSON.stringify(json,null,2));}</script>