婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > html頁面展示json數據并格式化的方法

html頁面展示json數據并格式化的方法

熱門標簽:強訊外呼系統 愛巢地圖標注 貴陽ai外呼系統 電銷外呼線路改不外呼線路 重慶人工智能電銷機器人報價 長春極信防封電銷卡公司 智能電銷機器人廣告語 crm外呼系統好不好 電話機器人批發

json數據在html頁面展示并格式化

一、展現效果圖

描述信息:

  • key值全部采用紅色標出,表示重要參數;
  • value值采用不同顏色標出,數值類型的采用橘黃色,字符串采用綠色,布爾采用藍色。。。

二、源代碼展示

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <style>
    pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
    .string { color: green; }
    .number { color: darkorange; }
    .boolean { color: blue; }
    .null { color: magenta; }
    .key { color: red; }

    .showinfo{
        position: absolute;
        background-color: #eef1f8;
        width: 200px;
        padding: 5px;
        border-radius: 4px;
        border: 1px solid #ccc;
        display: none;
    }
    .showinfo pre{
        padding: 5px;
        border: 1px solid #ccc;
        margin:0;
    }
    table,th,td{
        border:1px solid blue;
    }
</style>
<script src="./js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">

    $(document).ready(function(){
        $(".show-rough").mouseover(function(){
            var left = $(this).offset().left + $(this).width() +20;//計算div顯示位置
            var top = $(this).offset().top + 20;
            var _jsonDate = $.parseJSON($(this).text());
            var showJson = syntaxHighlight(_jsonDate);
            $("#show-info").css({"left":left,"top":top}).show();
            $("#show-pre").html(showJson);
        });
        $(".show-rough").mouseout(function(){
            $("#show-info").hide().html();
            $("#show-pre").html();
        })
    });
    //處理json數據,采用正則過濾出不同類型參數
	function syntaxHighlight(json) {
    if (typeof json != 'string') {
        json = JSON.stringify(json, undefined, 2);
    }
    json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
    return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function(match) {
        var cls = 'number';
        if (/^"/.test(match)) {
            if (/:$/.test(match)) {
                cls = 'key';
            } else {
                cls = 'string';
            }
        } else if (/true|false/.test(match)) {
            cls = 'boolean';
        } else if (/null/.test(match)) {
            cls = 'null';
        }
        return '<span class="' + cls + '">' + match + '</span>';
    });
};
</script>
</head>
<body>
<table>
    <thead>
        <tr>
            <th>姓名</th>
            <th>json數據</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>小三</td>
            <td class="show-rough">{ "name": "小三", "address":"北京路23號","age":16, "email": "123456@qq.com","Object":[{"職位":"經理"}],"del":[] }</td>
        </tr>
        <tr>
            <td>小四</td>
            <td class="show-rough">{ "name": "小四", "address":"上海路01號","age":27, "email": "222222@qq.com","Object":[],"del":[]  }</td>
        </tr>
    </tbody>
</table>
<div id="show-info" class="showinfo">
    <pre id="show-pre">

</pre>
</div>
</body>
</html>

三、源代碼上傳

源代碼下載地址

到此這篇關于html頁面展示json數據并格式化的方法的文章就介紹到這了,更多相關html展示json并格式化內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章,希望大家以后多多支持腳本之家!

標簽:保定 清遠 山南 上海 廣安 陜西 吳忠 內蒙古

巨人網絡通訊聲明:本文標題《html頁面展示json數據并格式化的方法》,本文關鍵詞  html,頁面,展示,json,數據,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《html頁面展示json數據并格式化的方法》相關的同類信息!
  • 本頁收集關于html頁面展示json數據并格式化的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 霍林郭勒市| 沂源县| 青浦区| 五峰| 宜昌市| 新乡县| 东山县| 秀山| 那坡县| 龙山县| 十堰市| 南投县| 宝山区| 凭祥市| 墨脱县| 洛南县| 金秀| 察雅县| 海兴县| 芮城县| 商都县| 巨鹿县| 赤城县| 怀安县| 伊吾县| 洛阳市| 黎川县| 宿州市| 金塔县| 普陀区| 石渠县| 五大连池市| 佛坪县| 太仓市| 平果县| 余庆县| 重庆市| 天镇县| 手游| 含山县| 西乡县|