自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

查詢json數(shù)據(jù)結(jié)構(gòu)的8種方式

開發(fā) 前端
你有沒有對“在復(fù)雜的JSON數(shù)據(jù)結(jié)構(gòu)中查找匹配內(nèi)容”而煩惱。這里有8種不同的方式可以做到。

你有沒有對“在復(fù)雜的JSON數(shù)據(jù)結(jié)構(gòu)中查找匹配內(nèi)容”而煩惱。這里有8種不同的方式可以做到:

JsonSQL

JsonSQL實現(xiàn)了使用SQL select語句在json數(shù)據(jù)結(jié)構(gòu)中查詢的功能。

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

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

JSONPath

JSONPath就像是針對JSON數(shù)據(jù)結(jié)構(gòu)的XPath。

例子:

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

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

jfunk

jFunk允許你檢索(很快會加入管理功能)復(fù)雜的JSON或Javascript對象。jFunk API的設(shè)計幾乎與jQuery API類似。它直接復(fù)制了jQuery的API,除了那些針對DOM的API。

例子:

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

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

TaffyDB

你過去有沒有注意到Javascript對象的字面值看起來很像記錄?如果你把他們包裹在一個數(shù)組里面,那么它們看起來有沒有像一個數(shù)據(jù)庫 表?TaffyDB是一個Javascript庫,它提供了強大的數(shù)據(jù)庫功能以實現(xiàn)之前的想法,大大改善了你在Javascript中使用數(shù)據(jù)的方式。

  1. var kelly = friends({id:2}).first(); 

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

linq.js

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

  1. var queryResult2 = Enumerable.From(jsonArray) 
  2.     .Where("$.user.id < 200") 
  3.     .OrderBy("$.user.screen_name") 
  4.     .Select("$.user.screen_name + ':' + $.text") 
  5.     .ToArray(); 

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

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

objeq

objeq是一個簡單的庫,實現(xiàn)了對POJSO(Plain-Old JavaScript Objects,普通的Javascript對象)的實時查詢。

  1. var res = $objeq(data, "age > 40 && gender == 'female' -> name"); 
  2.     // --> Returns ['Jessica'] 

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

(譯注:它使用了Javascript的property setters,所以它只能工作在較新的 瀏覽器上)

json:select()

使用類CSS選擇符來查詢JSON。

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

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

Paul的編程珠璣中的Javascript數(shù)組過濾方法

  1. var a = [1,2,3,4,5,6,7,8,9,10]; 
  2.  
  3.         // return everything 
  4.  
  5.         a.where( "( ) => true" ) ; 
  6.  
  7.         //  --> [1,2,3,4,5,6,7,8,9,10] 
  8.  
  9.         // return even numbers 
  10.  
  11.         a.where( "( n, i ) => n % 2 == 0" ) ; 
  12.  
  13.         //  --> [2,4,6,8,10] 
  14.  
  15.         // query first 6 products whose category begins with 'con' using extra param and regular expression 
  16.  
  17.         products.where( "( el, i, res, param ) => res.length <= 6 && param.test( el.cat )", /^con/i); 
  18.  
  19.         // using customer table data from SQL Server's northwind database...     
  20.  
  21.         customers.where( "( el, i, res, param ) => el.country == param", "USA" ); 

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

目前這是我最喜歡的查詢JSON數(shù)據(jù)結(jié)構(gòu)的方法。它非常的簡單,并且據(jù)作者所說它非???。

它背后的理念和 John Resig的JavaScript Micro-Templating類似:使用正確表達(dá)式將一段非常簡單的字符串轉(zhuǎn)換成Javascript函數(shù)。

當(dāng)然,還有更多強大的解決方案。 Paul實現(xiàn)的原型還缺少對過濾表達(dá)式的語法檢查,但是我相信你應(yīng)該可以自己解決Javscript的語法檢查。

***,你必須決定哪個對于你的項目來說***。

原文鏈接:http://itindex.net/detail/41114-json-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84

責(zé)任編輯:陳四芳 來源: 伯樂在線
相關(guān)推薦

2019-10-29 08:59:16

Redis底層數(shù)據(jù)

2020-08-03 07:48:15

Javascript數(shù)據(jù)結(jié)構(gòu)

2020-06-28 09:57:24

數(shù)據(jù)結(jié)構(gòu)算法

2020-09-18 09:13:46

數(shù)據(jù)結(jié)構(gòu)元素

2020-04-02 15:37:58

數(shù)據(jù)結(jié)構(gòu)存儲

2025-01-13 06:10:00

2020-03-04 11:10:14

數(shù)據(jù)結(jié)構(gòu)程序員編譯器

2023-09-06 13:16:00

數(shù)據(jù)庫數(shù)據(jù)

2020-03-02 13:45:18

Redis數(shù)據(jù)結(jié)構(gòu)Java

2021-07-14 23:55:18

數(shù)據(jù)結(jié)構(gòu)數(shù)組

2023-10-31 08:51:25

數(shù)據(jù)結(jié)構(gòu)存儲數(shù)據(jù)

2011-03-31 15:41:51

Cacti數(shù)據(jù)表結(jié)構(gòu)

2012-04-28 14:21:47

Java數(shù)據(jù)結(jié)構(gòu)線性結(jié)構(gòu)

2022-11-04 08:29:05

索引數(shù)據(jù)庫JSON

2023-07-03 17:24:33

數(shù)據(jù)結(jié)構(gòu)

2014-12-10 10:35:43

微信 數(shù)據(jù)結(jié)構(gòu)

2023-04-11 08:00:56

Redis類型編碼

2024-03-26 00:05:13

數(shù)據(jù)庫數(shù)據(jù)結(jié)構(gòu)

2020-10-21 14:57:04

數(shù)據(jù)結(jié)構(gòu)算法圖形

2021-05-12 14:09:35

鏈表數(shù)據(jù)結(jié)構(gòu)線性結(jié)構(gòu)
點贊
收藏

51CTO技術(shù)棧公眾號