本文介绍了JSON以漂亮的打印方式将输出转换为div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请使用 < pre> 标记
演示:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!