废话不多说了,直接给大家贴代码了,具体代码如下所示:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <link rel="stylesheet" href="https://rawgithub.com/yesmeck/jquery-jsonview/master/dist/jquery.jsonview.css" />
  <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
  <script type="text/javascript" src="https://rawgithub.com/yesmeck/jquery-jsonview/master/dist/jquery.jsonview.js"></script>
  <script type="text/javascript">
var json = {"hey": "guy","anumber": 243,"anobject": {"whoa": "nuts","anarray": [1,2,"thr<h1>ee"],"anotherarray": [1, 2], "more":"stuff"},"awesome": true,"bogus": false,"meaning": null, "japanese":"明日がある。", "link": "http://jsonview.com", "notLink": "http://jsonview.com is great"};
$(function() {
  $('#json').JSONView(json);
  $('#collapse-btn').on('click', function() {
    $('#json').JSONView('collapse');
  });
  $('#expand-btn').on('click', function() {
    $('#json').JSONView('expand');
  });
  $('#toggle-btn').on('click', function() {
    $('#json').JSONView('toggle');
  });
  $('#toggle-level1-btn').on('click', function() {
    $('#json').JSONView('toggle', 1);
  });
  $('#toggle-level2-btn').on('click', function() {
    $('#json').JSONView('toggle', 2);
  });
});
  </script>
</head>
<body>
  <br/>
  <button id="collapse-btn">Collapse</button>
  <button id="expand-btn">Expand</button>
  <button id="toggle-btn">Toggle</button>
  <button id="toggle-level1-btn">Toggle level1</button>
  <button id="toggle-level2-btn">Toggle level2</button>     <div id="json"></div>
</body>
</html>

如demo所示,显示格式化的json

以上所述是小编给大家介绍的html格式化json的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!