Possible Duplicate:
(可能重复:)
I know how to generate JSON from an object using JSON.stringify, or in my case the handy jquery-json from google code ( https://github.com/krinkle/jquery-json ).
(我知道如何使用JSON.stringify从对象生成JSON,或者在我的情况下从google代码( https://github.com/krinkle/jquery-json )生成方便的jquery-json。)
Now this works fine, but the output is hard to read for humans.
(现在这种方法很好,但输出很难为人类阅读。)
Is there an easy way / function / whatever to output a neatly formatted json file?(是否有简单的方法/功能/输出整齐格式的json文件?)
This is what I mean:
(这就是我的意思:)
JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}});
gives..
(使..)
"{"a":1,"b":2,"c":{"d":1,"e":[1,2]}}"
I'd like something like this instead:
(我喜欢这样的东西:)
{
"a":1,
"b":2,
"c":{
"d":1,
"e":[1,2]
}
}
Eg with newlines and tabs added.
(例如添加了换行符和标签。)
It's much easier to read for larger documents.(阅读更大的文档要容易得多。)
I'd like to do this ideally without adding any huge libraries - eg not prototype or YUI or whatever.
(我想在没有添加任何大型库的情况下理想地执行此操作 - 例如,不是原型或YUI或其他任何东西。)
ask by Ben Clayton translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…