html怎样格式化json数据


本文摘自PHP中文网,作者php中世界最好的语言,侵删。

这次给大家带来html怎样格式化json数据,html格式化json数据的注意事项有哪些,下面就是实战案例,一起来看一下。

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

<!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表格的边框?html table表格制作及实例

javascript怎么去掉页眉页脚

html怎么换行?换行代码是什么?九种html文字换行方法总结

html如何设置标题

border在html中是什么意思

如何快速查找html中的链接

html怎么设置文字大小

javascript中怎么将json对象转为字符串

html中的注释怎么写?html中的注释符号又是什么?(附实例)

如何实现炫酷的数字大屏

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...