0
点赞
收藏
分享

微信扫一扫

查询json数据结构的8种方式


JsonSQL

[color=red][b]JsonSQL实现了使用SQL select语句在json数据结构中查询的功能。[/b][/color]
例子:

jsonsql.query("select * from json.channel.items order by title desc",json);


主页:[url]http://www.trentrichardson.com/jsonsql/[/url]




[color=red][b]JSONPath[/b][/color]


JSONPath就像是针对JSON数据结构的XPath。



例子:


jsonPath( books,'$..book[(@.length-1)]')


主页:[url]http://goessner.net/articles/JsonPath/[/url]




[color=red][b]jfunk[/b][/color]


jFunk允许你检索(很快会加入管理功能)复杂的JSON或Javascript对象。jFunk API的设计几乎与jQuery API类似。它直接复制了jQuery的API,除了那些针对DOM的API。



例子:


Jf("> vegetables > *[color=Orange]",Food).get();


主页:[url]http://code.google.com/p/jfunk/[/url]




[color=red][b]TaffyDB[/b][/color]



你过去有没有注意到Javascript对象的字面值看起来很像记录?如果你把他们包裹在一个数组里面,那么它们看起来有没有像一个数据库表?TaffyDB是一个Javascript库,它提供了强大的数据库功能以实现之前的想法,大大改善了你在Javascript中使用数据的方式。


varkelly = friends({id:2}).first();


主页:[url]http://www.taffydb.com/[/url]




[color=red][b]linq.js[/b][/color]



linq.js——Javascript中的LINQ(译者注:.Net中的概念,见http://msdn.microsoft.com/zh-tw/library/bb397897)


varqueryResult2 = Enumerable.From(jsonArray)
    .Where("$.user.id < 200")
    .OrderBy("$.user.screen_name")
    .Select("$.user.screen_name + ':' + $.text")
    .ToArray();


主页:[url]http://linqjs.codeplex.com/[/url]



主页:[url]http://neue.cc/reference.htm[/url]




[color=red][b]objeq[/b][/color]



objeq是一个简单的库,实现了对POJSO(Plain-Old JavaScript Objects,普通的Javascript对象)的实时查询。


varres = $objeq(data,"age > 40 && gender == 'female' -> name");
    // --> Returns ['Jessica']


主页:[url]https://github.com/agilosoftware/objeq[/url]



(译注:它使用了Javascript的property setters,所以它只能工作在较新的浏览器上)



json:select()



使用类CSS选择符来查询JSON。


.lang:val("Bulgarian") ~ .level


主页:[url]http://jsonselect.org/#tryit[/url]




[color=red][b]Paul的编程珠玑中的Javascript数组过滤方法 [/b][/color]


vara = [1,2,3,4,5,6,7,8,9,10];

        // return everything

        a.where("( ) => true") ;

        //  --> [1,2,3,4,5,6,7,8,9,10]

        // return even numbers

        a.where("( n, i ) => n % 2 == 0") ;

        //  --> [2,4,6,8,10]

        // query first 6 products whose category begins with 'con' using extra param and regular expression

        products.where("( el, i, res, param ) => res.length <= 6 && param.test( el.cat )", /^con/i);

        // using customer table data from SQL Server's northwind database...   

        customers.where("( el, i, res, param ) => el.country == param","USA");


主页:http://www.paulfree.com/28/javascript-array-filtering/#more-28



目前这是我最喜欢的查询JSON数据结构的方法。它非常的简单,并且据作者所说它非常快。


举报

相关推荐

0 条评论