1 Star 0 Fork 15

搬砖男子汉 / jsonFormater

forked from leo108 / jsonFormater 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

JsonFormater

基于jQuery的json格式化、高亮库

核心代码参考天马行空工作室,本人只做了模块化和一些代码优化。

demo

http://leo108.github.io/jsonFormater/

使用方式

引入jQuery

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>

注意:jQuery版本要求>=1.7.2

引入jsonFormater.js和jsonFormater.css

<script type="text/javascript" src="jsonFormater.js"></script>

<link href="jsonFormater.css" type="text/css" rel="stylesheet"/>

在html中新增一个空的元素作为显示的容器

例如<div id='container'></div>

调用JsonFormater

$(document).ready(function(){
    var options = {
        dom : '#container' //对应容器的css选择器
    };
    var jf = new JsonFormater(options); //创建对象
    jf.doFormat('{"string":"leo108"}'); //格式化json
});

效果图

效果图

详细使用方式

配置

支持的配置以及默认配置如下:

{
    dom: '',          //用于放置的dom的选择器
    singleTab: "  ",  //单个tab
    tabSize: 2,       //缩进数量
    quoteKeys: true,  //key是否用双引号包含
    imgCollapsed: "images/Collapsed.gif", //收起的图片路径
    imgExpanded: "images/Expanded.gif",  //展开的图片路径
    isCollapsible: true //是否支持展开收起
}

方法

obj.doFormat(json)格式化一个json字符串或者js对象

obj.expandAll()全部展开

obj.collapseAll()全部收起

obj.collapseLevel(level)展开到level层

The MIT License (MIT) Copyright (c) 2014 leo108 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

json格式化+高亮 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/banzhuannanzihan/jsonFormater.git
git@gitee.com:banzhuannanzihan/jsonFormater.git
banzhuannanzihan
jsonFormater
jsonFormater
master

搜索帮助