index.html 1.64 KB
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../../css/tool/bootstrap.css">
<link href="../../css/tool/jquery.json-viewer.css" type="text/css" rel="stylesheet" />
<style>
	body{background-color: #F7F7F7}
</style>
</head>
<body>
<div class="jq22-container">
  <div class="container"  style="margin-top: 1em;">
    <div class="row">
      <textarea class="form-control" id="json-input" rows="15" >
	  </textarea>
      <label class="checkbox-inline">
        <input type="checkbox" id="collapsed">
        收缩所有的节点 </label>
      <label class="checkbox-inline">
        <input type="checkbox" id="with-quotes">
        为Key添加双引号 </label>
      <div class="form-group" style="padding: 1em 0;">
        <button id="btn-json-viewer" class="btn btn-info" title="run jsonViewer()">转换Json数据</button>
      </div>
      <pre id="json-renderer"></pre>
    </div>
  </div>
  
<script src="jQuery-2.1.4.min.js"></script>
<script src="jquery.json-viewer.js"></script> 
<script type="text/javascript">
	 	$(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>
</body>
</html>