This time I will show you how to format json data in html. What are the precautions for formatting json data in html? The following is a practical case, let's take a look.
No more nonsense, let me just post the code for you. The specific code is as follows:<!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>
How to use the img tag of HTML images
What are the name, id and class in HTML? What's the difference
Detailed explanation of meta columns in HTML5's WEB interface
The above is the detailed content of How to format json data in html. For more information, please follow other related articles on the PHP Chinese website!