json-viewer.js json结构化美化格式化插件

json-viewer.js json结构化美化格式化插件

第一步引入bfwone

第二步执行插件代码

示例如下

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>BFW NEW PAGE</title>
    <script id="bfwone" data="dep=jquery.17&err=0" type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/bfwone.js"></script>
    <script type="text/javascript">
        bready(function() {
            use(["json-viewer", "json-viewer"], function() {
                var jsonstr = $("#json_data_cont").val();

                $('#json-renderer').jsonViewer(JSON.parse(jsonstr));
                $("#json_data_cont").on("paste", function() {

                    setTimeout(function() {
                        try {
                            var jsonstr = $("#json_data_cont").val();

                            $('#json-renderer').jsonViewer(JSON.parse(jsonstr));
                        }catch(e) {
                            alert(e.message);
                        }
                    }, 500);



                });
            });
        });
    </script>
</head>
<body>
    <div>

        <textarea id="json_data_cont" style="width:100%;height:300px;">
            {
            "name": "bfwone",
            "url": "http://one.bfw.wiki",
            "page": 88,
            "isNonProfit": true,
            "address": {
            "street": "武进区",
            "city": "江苏常州",
            "country": "中国"
            },
            "links": [
            {
            "name": "Google",
            "url": "http://www.google.com"
            },
            {
            "name": "Baidu",
            "url": "http://www.baidu.com"
            },
            {
            "name": "SoSo",
            "url": "http://www.SoSo.com"
            }
            ]
            }
        </textarea>
    </div>
    <pre id="json-renderer"></pre>
</body>
</html>


立即下载json-viewer.js查看所有js插件

网友评论0

程序员在线工具箱