首页 > 技术文章 > HTML页面直接显示json 结构

AllenChou 2017-10-17 11:51 原文

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">
        #songResJson{
            border: 1px solid #8d8c8c;
            padding: 5px;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
    </style>
</head>
<body>
    <div class="apiResult">
    <h2> json 数据</h2>
    <pre id="songResJson"></pre>  
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script>
    var data = {
        "ret": 0,
          "msg": "success",
          "data": []
    };
    $("#songResJson").text(JSON.stringify(data,null,2)); 
</script>
</body>
</html>

结构展示

 

推荐阅读