`

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

 
阅读更多
http://my.oschina.net/frankies/blog/396810
JsonSQL

JsonSQL实现了使用SQL select语句在json数据结构中查询的功能。
例子:
jsonsql.query("select * from json.channel.items order by title desc",json);

主页:http://www.trentrichardson.com/jsonsql/



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

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

主页:http://goessner.net/articles/JsonPath/



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

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

主页:http://code.google.com/p/jfunk/



TaffyDB

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

主页:http://www.taffydb.com/



linq.js

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();

主页:http://linqjs.codeplex.com/

主页:http://neue.cc/reference.htm



objeq

objeq是一个简单的库,实现了对POJSO(Plain-Old JavaScript Objects,普通的Javascript对象)的实时查询。
varres = $objeq(data,"age > 40 && gender == 'female' -> name");
    // --> Returns ['Jessica']

主页:https://github.com/agilosoftware/objeq

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

json:select()


使用类CSS选择符来查询JSON。
.lang:val("Bulgarian") ~ .level

主页:http://jsonselect.org/#tryit



Paul的编程珠玑中的Javascript数组过滤方法
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数据结构的方法。它非常的简单,并且据作者所说它非常快。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics