页面格式化json


我有一个需求是:把后端返回的json展示给客户看,所以需要格式化输出json,不知道有没有什么工具啊?查了一下全是jsonview之类的,这是给RD用的不是给用户的啊…

json

卖女孩的小柴火 8 years, 6 months ago

我之前练手写了一个,不知道有没有用,看能给你提供思路不。 https://github.com/hjzheng/JSONFormatter

8158432 answered 8 years, 6 months ago

把后端返回的json展示给客户看,所以需要格式化输出json?
这是要输出json,还是把json的数据提出来再格式化?
原生js就能格式化json

春哥D纯爷们 answered 8 years, 6 months ago

后端返回的直接展现在页面上不就好了

隐身裸飘饭桶女 answered 8 years, 6 months ago

在 JSFIDDLE 上看效果

http://jsfiddle.net/br7yfx2j/


 var json = '{"color_scheme":"Packages/Predawn/predawn.tmTheme","default_line_ending":"unix","findreplace_small":true,"font_face":"Source Code Pro","font_options":["no_bold","no_italic"],"font_size":11,"ignored_packages":["Markdown","Vintage"],"rulers":[80,100,120],"shift_tab_unindent":true,"show_encoding":true,"show_line_endings":true,"tab_size":4,"tabs_medium":true,"theme":"predawn.sublime-theme","translate_tabs_to_spaces":true,"typescript_plugin_tsc_version":"1.6.2","word_wrap":true}'

var result = JSON.stringify(JSON.parse(json), null, 4);

// 用 jQuery
$("<pre>").text(result).appendTo($("body"));

魔法G一喵喵 answered 8 years, 6 months ago

Your Answer