可能重複:
JSON pretty print using JavaScript美化JSON數組中的JavaScript
我的工作,這將被用來幫助分析,並通過平臺的未來開發者瞭解JSON陣列項目。我正在引用Facebook輝煌的Graph Explorer頁面seen here,並且希望在美化,正確製表符縮進和斷行數組中輸出我們的數組,就像它在瀏覽器上一樣。
該陣列輸出到textarea
,正因爲如此,我認爲我遇到了斷線和跳閘的問題。我也試過使用美化庫,但沒有運氣。
例子:
{"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
}
參見http://stackoverflow.com/questions/2614862/how-can-i-beautify-json-programmatically – 2012-07-06 09:18:13
還有http://www.jsonlint.com/ - 如果這' d通過減輕您的工作量來幫助您! :) – 2012-07-06 09:29:05
@limelights這看起來像一個很好的工具,但是數組總是有效的,所以我們不需要測試它們,更多的只是將它們更整齊地可視化。 – 2012-07-06 09:32:59