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

[url]http://my.oschina.net/frankies/blog/396810[/url]
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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值