将json 数据以美观的缩进格式显示出来,借助最简单的JSON.stringify 函数就可以了,因为此函数还有不常用的后面2个参数。
Consulte MDN https://developer.mozilla.org/zh-docs/web/javascript/reference/global_objects/json/stringify.
El código de ejemplo es el siguiente:
html; : green;} .number {color: darkorange;} .Boolean {color: blue;}. Null {color: magenta;} .Key {color: red;} </style> <script type = text// javascript> Function Sintaxhighlight (json) {if (typeof json! = 'String') {json = json.stringify (json, undefined, 2);} json = json.replace (/&/g, '&'). </g, '<<'). ^U] | ] [+/-]?/D +)?)/g, function (match) {var cls = 'number'; ) {Cls = 'key';} else {class = 'string';}} else if (/true | false/.test (match)) {cls = 'boolean'; } Return '<span class =' + class + '>' + match + '</span>';}); ALL, qt: 581, content: { answer: { song: 如果缘只到遇见, album: 如果缘只到遇见, artist : Wu Qilong Yan Yidan, pic_url: http://p1.music.126.net/- u3wgixsfncw7d8jy7pcea==/5921969627395387.jpg}, Scene: Music}} 'Result'). InnerHtml = SyntaxHighlight (songresjson) ; // $ ('#Result'). HTML (Syntaxhighlight (Songresjson)); </Script> </ Cuerpo> </html>Lo anterior es todo el contenido de este artículo.