JSON在線格式化 jsoneditor使用


 

    const placeholder = {
        string: 'hello world!',
        boolean: true,
        color: '#6c928c',
        number: 123,
        null: null,
        array: [1, 2, 3],
        object: {a: 'b', c: 'd', e: 'f'}
    };
    const json_editor = new JSONEditor(document.getElementById("json_editor"), {mode: 'code'}, placeholder);
    const tree_editor = new JSONEditor(document.getElementById("tree_editor"), null, placeholder);
    tree_editor.expandAll();

    function toTree() {
        tree_editor.set(JSON.parse(json_editor.getText()));
        tree_editor.expandAll();
    }

    function toJson() {
        json_editor.setText(JSON.stringify(tree_editor.get(), null, 2))
    }

  實現效果

~~~

在線DEMO(https://oktools.net/json)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM