JosnIndex.cshtml 1.65 KB
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@section header
{
    <link href="~/css/homecss/bootstrap.min.css" rel="stylesheet" />
    <link href="~/js/json/jquery.json-viewer.css" rel="stylesheet" />
    <style type="text/css">
        #json-renderer {
            height: 400px;
            overflow-y: auto;
        }
         
    </style>
}
<div class="container" style="margin-top: 1em;">
    <div class="row">
        <textarea class="form-control" id="json-input" rows="5" placeholder="请输入正确的json格式数据"></textarea>
        <label class="checkbox-inline">
            <input type="checkbox" id="collapsed">收缩所有的节点
        </label>
        <div class="form-group">
            <button id="btn-json-viewer" class="btn btn-info" title="run jsonViewer()">转换Json数据</button>
        </div>
        <pre id="json-renderer"></pre>
    </div>
</div>

@section Scripts
{
    <script src="~/js/jQuery-2.1.4.min.js"></script>
    <script src="~/js/json/jquery.json-viewer.js"></script>
    <script>
        $(function () {
            $('#btn-json-viewer').click(function () {
                try {
                    var input = eval('(' + $('#json-input').val() + ')');
                }
                catch (error) {
                    return alert("Cannot eval JSON: " + error);
                }
                var options = {
                    collapsed: $('#collapsed').is(':checked'),
                    withQuotes: $('#with-quotes').is(':checked')
                };
                $('#json-renderer').jsonViewer(input, options);
            });

        });
    </script>
}