html页面输出json数据,带格式,带中文
生活随笔
收集整理的這篇文章主要介紹了
html页面输出json数据,带格式,带中文
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
<!DOCTYPE html> <html> <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; } </style> <head><meta charset="utf-8"><title>JSON格式化</title><script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script><script>$(document).ready(function(){var result = {"status": 1,"data": {"total": 3,"page": 1,"limit": 10,"list": [{"title": '測試1',"title1": '測試2',"title3": '中文',"title4": '簡體'}]},"message": "success","$dateTime": "2019-05-17 06:35:24","$timestamp": 1558074924};$('#result').html(syntaxHighlight(result));});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> <pre id="result"> </pre> </body> </html>轉(zhuǎn)載于:https://my.oschina.net/shmilyle/blog/3050859
總結(jié)
以上是生活随笔為你收集整理的html页面输出json数据,带格式,带中文的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos7查看udp端口_CentO
- 下一篇: win10商店无法打开,错误0x8013