偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

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

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

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

JsonSQL

JsonSQL實(shí)現(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就像是針對(duì)JSON數(shù)據(jù)結(jié)構(gòu)的XPath。

例子:

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

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

jfunk

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

例子:

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

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

TaffyDB

你過去有沒有注意到Javascript對(duì)象的字面值看起來很像記錄?如果你把他們包裹在一個(gè)數(shù)組里面,那么它們看起來有沒有像一個(gè)數(shù)據(jù)庫 表?TaffyDB是一個(gè)Javascript庫,它提供了強(qiáng)大的數(shù)據(jù)庫功能以實(shí)現(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是一個(gè)簡單的庫,實(shí)現(xiàn)了對(duì)POJSO(Plain-Old JavaScript Objects,普通的Javascript對(duì)象)的實(shí)時(shí)查詢。

  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)然,還有更多強(qiáng)大的解決方案。 Paul實(shí)現(xiàn)的原型還缺少對(duì)過濾表達(dá)式的語法檢查,但是我相信你應(yīng)該可以自己解決Javscript的語法檢查。

***,你必須決定哪個(gè)對(duì)于你的項(xiàng)目來說***。

原文鏈接: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)元素

2025-01-13 06:10:00

2020-04-02 15:37:58

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

2025-05-13 08:05:00

Redis數(shù)據(jù)類型數(shù)據(jù)庫

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

2023-10-31 08:51:25

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

2011-03-31 15:41:51

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

2021-07-14 23:55:18

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

2012-04-28 14:21:47

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

2023-07-03 17:24:33

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

2014-12-10 10:35:43

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

2022-11-04 08:29:05

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

2023-04-11 08:00:56

Redis類型編碼

2021-05-12 14:09:35

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

2020-10-21 14:57:04

數(shù)據(jù)結(jié)構(gòu)算法圖形
點(diǎn)贊
收藏

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