JSON をきれいに/美化するサイトについて聞いたことがあります。それは実際にはどういう意味ですか?
4 に答える
7
これは、より人間が読めるバージョンであることを意味します。たとえば、次は有効な 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-15T07:40:41.593 に答える
1
コードをきれいにします。つまり、コードをインデントし、同様の方法で整列させ、すべての括弧を同様の方法で配置します。
例
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
ただし、自分で実行したい場合は、2 番目のパラメーターを関数として使用できます。JSON.stringify
関数の詳細については、こちらを参照してください。
JSON文字列をきれいに印刷する方法の多くの例。
于 2011-04-15T07:39:28.970 に答える
0
貼り付けたJSONを美化してくれるサイトがこちらで見れます...
主にデバッグ目的で、読みやすくなっていると思います。
于 2011-04-15T07:39:01.177 に答える