ObjTree.js实现json对象与xml格式之间相互转换示例代码

代码语言:html

所属分类:其他

代码描述:使用ObjTree.js插件你实现json对象与xml格式之间相互转换并复制下载示例代码

代码标签: json xml 转换

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

   <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
            <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ObjTree.js"></script>
            <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/filesaver.js"></script>
</head>

<body>




    <div class='container'>


        <div>
            <button onclick="javascript:demo_xml();">示例XML</button>
            <button onclick="javascript:demo_json();">示例JSON</button>
        </div>
        <textarea placeholder="贴入要转换的JSON或者XML代码" id="input" style="height:200px;width:100%;"></textarea>
        <div>
            <button onclick="javascript:xml_2_json();">XML转JSON</button>
            <button onclick="javascript:json_2_xml();">JSON转XML</button>
            <input type="checkbox" id="pretty_json" checked="">PRETTY JSON
            <textarea placeholder="转换之后的XML或者JSON代码" id="output" style="height:200px;width:100%;"></textarea>
            <div>
                <div><span id="message" class="green"></span></div>
            </div>
            <div class='row'>
                <button type="button" onclick="save_file();">保存文本</button>
                <button type="button" onclick="Empty();">清空结果</button>
            </div>
         
            <script type="text/javascript">
                var outtype="";
                            			function demo_xml() {
var xml = "<books>\
<book>\
<author>Auther1</author>\
<title>Book1</title>\
</book>\
<book>\
<author>Auther2</author>\
<title>Book2</title>\
 </book>\
 </books>";
$('#input').val(xml);
                            			}
                            			function demo_json() {
                            				var json = '{\
                            	"tools": [\
                            	{ "name":"css format" , "site":"https://tool.bfw.wiki/tool/1559286383549195.html" },\
                            	{ "name":"json format" , "site":"https://tool.bfw.wiki/tool/1559557892293068.html" }\
                            	]\
                            	}';
                            				$('#input').val(json);
                            			}
                            			function .........完整代码请登录后点击上方下载按钮下载查看

网友评论0