json 打印
// source http://jsbin.com/xogixepaju
<!DOCTYPE html>
<html>
<head>
<title>json 打印</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style type='text/css'>
<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>
</style>
</head>
<body>
<pre id="result">
</pre>
<script type="text/javascript">
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>';
});
}
var res = {"previous":"002219eac58d6764c204418603452563dedeec76c84ef5aa6db35c329aaf3455","timestamp":"2018-05-12T02:27:47.000","transaction_mroot":"50c49795b00639f964c48560a7c82adbf76e41ea2553fd72f2a64adfbdc5c002","action_mroot":"002e47e39e320c6dac84ab4c3d9543ac75d568f5a7d0950aa3f032845b815a7d","block_mroot":"be26c3c93f6080c1b4418f561b52f4e18c8cd9b2623c96bf4f97bd2e2efa3dca","producer":"eosio","schedule_version":0,"new_producers":null,"producer_signature":"EOSK7rsKdn2aqbbBTYHGogZNo5qnBajTwsbmExru97inx7Qenk5TpRXKyFfCCxcryXfpTFVdsaPqhMjhsp7XBPPCXSLbKjH5x","regions":[{"region":0,"cycles_summary":[[{"read_locks":[],"write_locks":[],"transactions":[{"status":"executed","kcpu_usage":2,"net_usage_words":38,"id":"05644cd2f729b50c01c3d33f276efbdfbc9655447cf48b5423ecb88728ad8f76"}]}]]}],"input_transactions":[],"id":"002219eb46a0ef0f8fad4fb5fac1a2bdb0956292156e0eb1c2fdb02a9a20ebf8","block_num":2234859,"ref_block_prefix":3041897871};
//document.getElementById('result').innerHtml = syntaxHighlight(res);
$('#result').html(syntaxHighlight(res));
</script>
</body>
</html>