JSON資料查詢方法
阿新 • • 發佈:2018-12-29
在進行前端專案開發的時候時長會遇到JSON的資料查詢問題,如何方便快速查詢?這裡推薦一個linqjs元件,專案主頁參見http://linqjs.codeplex.com/
查詢物件
var jsonArray = [ { "user": { "id": 100, "screen_name": "d_linq" }, "text": "to objects" }, { "user": { "id": 130, "screen_name": "c_bill" }, "text": "g" }, { "user": { "id": 155, "screen_name": "b_mskk" }, "text": "kabushiki kaisha" }, {"user": { "id": 301, "screen_name": "a_xbox" }, "text": "halo reach" } ] // ["b_mskk:kabushiki kaisha", "c_bill:g", "d_linq:to objects"] var queryResult = Enumerable.From(jsonArray) .Where(function (x) { return x.user.id < 200 }) .OrderBy(function (x) { return x.user.screen_name }) .Select(function (x) { return x.user.screen_name + ':' + x.text }) .ToArray(); // shortcut! string lambda selector var queryResult2 = Enumerable.From(jsonArray) .Where("$.user.id < 200") .OrderBy("$.user.screen_name") .Select("$.user.screen_name + ':' + $.text") .ToArray();