安装:jquery-jsonview
"jquery-jsonview": "^1.2.3",
@import " ../node_modules/jquery-jsonview/dist/jquery.jsonview.css";
declare var require: any
require('jquery-jsonview');
使用:
if(data==null||data==undefined) return;
data = data.replace(/\'/g, "\"");
console.log('try前');
try {
console.log('try');
jQuery("#parseJson").JSONView(data, {collapsed: true, nl2br: true, recursive_collapser: true})
console.log('try内');
} catch (e) {
console.log('catch');
var text = `<pre>${data}</pre>`
jQuery("#parseJson").html(text)
}
参考:https://blog.csdn.net/Lay_Ko/article/details/81448606
https://www.cnblogs.com/charlie-joie/p/7905173.html