JSON以漂亮的打印方式将输出转换为div [英] JSON.stringify output to div in pretty print way
问题描述
result = JSON.stringify(message,my_json,2)
2 $上面的参数中的c $ c>应该可以很好地打印结果。它做到这一点,如果我做一些像
alert(result)
。但是,我想通过在div内添加它来将其输出给用户。当我这样做时,我只会看到一条线。 (我不认为这是工作,因为休息和空格不被解释为HTML?)
$ b $
{data :{x:1,y:1,url:http://url.com},event:start,show:1,id :50}
有没有办法输出的结果JSON.stringify
以漂亮的打印方式转换为div?
请使用 < pre>
标记
演示: http://jsfiddle.net/K83cK/
I JSON.stringify
a json object by
result = JSON.stringify(message, my_json, 2)
The 2
in the argument above is supposed to pretty print the result. It does this if i do something like alert(result)
. However, I want to output this to the user by appending it inside a div. When I do this I get just a single line showing up. (I don't think it is working because the breaks and spaces are not being interpreted as html?)
{ "data": { "x": "1", "y": "1", "url": "http://url.com" }, "event": "start", "show": 1, "id": 50 }
Is there a way to output the result of JSON.stringify
to a div in a pretty print way?
Please use a <pre>
tag
demo : http://jsfiddle.net/K83cK/
这篇关于JSON以漂亮的打印方式将输出转换为div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!