下午没事干,到处闲逛发现一个好玩的东东,发出来与大家共享,哈哈。。。一个解析JSON的插件,
用SQL语法,当然只能用简单的条件查询咯,不过这个用起比较简单,容易上手,废话不多说下面就上code:
Dome下载:JsonSQL Dome下载
这编辑器不知道咋用,效果可能运行不了。。。不过有个Dome,需要的下载玩玩。。。
运行示例:
语句1: jsonsql.query("select * from json.channel.items order by title desc",json);
获取全部数据
语句2: jsonsql.query("select title,url from json.channel.items where (category=='javascript' || category=='vista') order by title,category asc limit 3",json);
获取过滤数据
语句3:jsonsql.query("select url from json.channel.items where (category=='javascript' && author=='trent') order by url asc limit 1,2",json);
获取限定数量的数据
参数详解:
只支持 Select 查询语句,“JSON”:“json.channel.items”指向一个对象数组, 排序接受参数:asc,desc,ascnum,descnum, limit:接受1,或2个参数,指定要获取数据数量个数。
调用JS方法:
function getAll(){
$.getJSON("testjson.js", function(json){
dump(jsonsql.query("select * from json.channel.items order by title desc,json",json));
});
}
function getFiltered(){
$.getJSON("testjson.js", function(json){
dump(jsonsql.query("select title,url,author,category from json.channel.items where (category=='javascript' || author=='trent') order by title,category asc limit 3",json));
});
}
function getLimit(){
$.getJSON("testjson.js", function(json){
dump(jsonsql.query("select url from json.channel.items where (category=='javascript' && author=='trent') order by url asc limit 1,2",json));
});
}
调用外部JS文件:
:输出文件样式文件
取得数据效果图:
转载于:https://www.cnblogs.com/zhangchen/archive/2011/11/28/2266499.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)