我听说过美化/美化JSON的网站。这到底是什么意思呢?
发布于 2011-04-15 15:40:42
这意味着它的可读性更强。例如,以下代码是有效的json,但可读性不佳:
{"outcome" : "success", "result" : {"name" : "messaging-sockets", "default-interface" : "external", "include" : [], "socket-binding" : {"messaging" : {"name" : "messaging", "interface" : null, "port" : 5445, "fixed-port" : null, "multicast-address" : null, "multicast-port" : null}, "messaging-throughput" : {"name" : "messaging-throughput", "interface" : null, "port" : 5455, "fixed-port" : null, "multicast-address" : null, "multicast-port" : null}}}, "compensating-operation" : null}
在美化之后,它可能看起来像这样:
{
"outcome":"success",
"result":{
"name":"messaging-sockets",
"default-interface":"external",
"include":[
],
"socket-binding":{
"messaging":{
"name":"messaging",
"interface":null,
"port":5445,
"fixed-port":null,
"multicast-address":null,
"multicast-port":null
},
"messaging-throughput":{
"name":"messaging-throughput",
"interface":null,
"port":5455,
"fixed-port":null,
"multicast-address":null,
"multicast-port":null
}
}
},
"compensating-operation":null
}
发布于 2011-04-15 15:39:29
它使你的代码看起来很漂亮,比如缩进它,确保内容以类似的方式对齐,所有的括号都以类似的方式放置,等等。
示例
var obj = {apple: {red: 5, green: 1}, bananas: 9}; //JS object
var str = JSON.stringify(obj, null, 4); // spacing level 4, or instead of 4 you can write "\t" for tabulator
//The third argument from stringify function enables pretty printing and sets the spacing to use.
console.log(str); //now you can see well pretty printed JSON string in console
但是如果你想在你自己身上这样做,那么你可以使用第二个参数作为函数。有关JSON.stringify
函数的更多信息,可以在here中找到。
发布于 2011-04-15 15:39:01
您可以看到一个站点here,它将美化粘贴的JSON...
它只是使它更具可读性,我想主要是为了调试目的。
https://stackoverflow.com/questions/5673706
复制相似问题