JSON格式页面展示美化方法
2014-06-29 21:06
267 查看
{"name": "monkey","age": "24","height": 164.0}
如果想让以上son字符串在页面上展示的比较易读,即变成下面的style:
{ "name": "monkey", "age": "24", "height": 164.0cm }
本文介绍的方法基于javascript ,代码如下:
<html> <head>/ //style中是css代码 <style type="text/css"> body { white-space: pre; font-family: monospace; } </style> //script中是javascript代码 <script> window.error_id_msgs = <%= error_id_msgs | raw %>; function myFunction() { document.body.innerHTML = ""; document.body.appendChild(document.createTextNode(JSON.stringify(window.error_id_msgs, null, 4))); } </script> </head> <body onload="myFunction()"> //表示页面加载时调用myFunction() </body> </html>
其中window.error_id_msgs是所要转换的json对象,css和myFunction结合可实现页面展示转换.
相关文章推荐
- 基于javascript的JSON格式页面展示美化方法
- 基于javascript的JSON格式页面展示美化方法
- web页面上可视化展示JSON数据的方法
- 在Html页面中,展示出Json格式数据,且保持缩进格式
- web页面上可视化展示JSON数据的方法
- spring mvc 中通过responsebody返回json格式到jsp页面乱码解决方法
- 在jQueryEasyUI中把表单内容转化成json格式的方法并且把查询到的结果显示到页面上
- jquery里面调用getjson方法,将list类型转换为json格式数据,在页面迭代显示
- 后台JSON接收为毫秒数,在前台页面展示yyyy-MM-dd格式
- jquery里面调用getjson方法,将list类型转换为json格式数据,在页面迭代显示
- c# 扩展方法奇思妙用 ASP.NET MVC 篇:巧用扩展方法优先级,美化所有页面 TextBoxFor 文本框
- php下哪种方法合适解析xml,转换成json格式
- GBK的页面输出JSON格式的php函数
- 步步为营:Asp.Net序列化Json格式的两种方法
- 两种方法接口aspx页面的编写(页面展示xml文档)
- 一种将数据表DataTable转为JSON格式的新方法
- 一种将数据表DataTable转为JSON格式的新方法
- 两种方法在Django框架中支持后台返回包含中文的JSON/数组格式
- jQuery1.4.2与老版本json格式兼容的解决方法
- 集合转json格式方法封装