http://leo108.com/pid-1996.asp
JsonFormater
基于jQuery的json格式化、高亮库
核心代码参考天马行空工作室,本人只做了模块化和一些代码优化。
demo
http://leo108.github.io/jsonFormater/
github地址
https://github.com/leo108/jsonFormater
使用方式
引入jQuery
1 |
<script type= "text/javascript" src= "jquery-1.7.2.min.js" ></script> |
注意:jQuery版本要求>=1.7.2
引入jsonFormater.js和jsonFormater.css
1 |
<script type= "text/javascript" src= "jsonFormater.js" ></script> |
2 |
<link href= "jsonFormater.css" type= "text/css" rel= "stylesheet" /> |
在html中新增一个空的元素作为显示的容器
例如<div id='container'></div>
调用JsonFormater
1 |
$(document).ready( function (){ |
5 |
var jf = new JsonFormater(options); |
6 |
jf.doFormat( '{"string":"leo108"}' ); |
效果图
![效果图](https://camo.githubusercontent.com/6926b7c6a5c72758c00a3cf3f91d6e9348206706/687474703a2f2f6c656f3130382e6769746875622e696f2f6a736f6e466f726d617465722f696d616765732f64656d6f2e706e67)
详细使用方式
配置
支持的配置以及默认配置如下:
6 |
imgCollapsed: "images/Collapsed.gif" , |
7 |
imgExpanded: "images/Expanded.gif" , |
方法
1 |
var obj = new JsonFormater({dom: '#container' }); |
5 |
obj.collapseLevel(level) |