DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: pixelcraft
今日帖子: 56
在线用户: 7
导航: 论坛 -> 开源项目 斑竹:joki,ralf_jones  
作者:
男 earthsbest (全能中间件) ▲▲▲▲△ -
普通会员
2018/5/17 10:03:35
标题:
高效、简洁、开源的JSON库-Neslib.Json 浏览:2936
加入我的收藏
楼主: 地址:https://github.com/neslib/Neslib.Json

JSONPath Examples
Example document:

{ "store": {
    "book": [
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}
Example paths:

Expression  Result
$  Matches the root document (a single value)
$..*  Matches all members in the document (lots of values)
$.store.book[*].author  The authors of all books in the store
$..author  All authors
$.store.*  All things in store (2 books and a bicycle)
$.store..price  The price of everything in the store
$..book[2]  The third book
$..book[-1:]  The last book in order
$..book[:2]  The first two books
JSONPath in Delphi
The JSONPath API is short and simple. It consists of a TJsonPath record with only a couple of methods.

For one-off matching, use the static Match method:

var
  Doc: IJsonDocument;
  Matches: TArray<TJsonValue>;
begin
  Doc := TJsonDocument.Load(...);
  Matches := TJsonPath.Match(Doc, '$.store.book[*].author');
end;
If you plan to use the same path on multiple (sub)documents, then it is faster to parse the path once, and then apply it multiple times:

var
  Doc1, Doc2: IJsonDocument;
  Path: TJsonPath;
  Matches1, Matches2: TArray<TJsonValue>;
begin
  Doc1 := TJsonDocument.Load(...);
  Doc2 := TJsonDocument.Load(...);

  Path := TJsonPath.Create('$.store.book[*].author');
    
  Matches1 := Path.Match(Doc1);
  Matches2 := Path.Match(Doc2);
end;
You can also run the path on sub-trees:

var
  Doc: IJsonDocument;
  Store: TJsonValue;
  Matches: TArray<TJsonValue>;
begin
  Doc := TJsonDocument.Load(...);
  Store := Doc.Root.Values['store'];
  Matches := TJsonPath.Match(Store, '$.book[*].author');
end;
If you are only interested in a single (or the first) match, then you can use MatchSingle instead:

var
  Doc: IJsonDocument;
  Match: TJsonValue;
begin
  Doc := TJsonDocument.Load(...);
  if (TJsonPath.MatchSingle(Store, '$.book[*]', Match)) then
    ...
end;
----------------------------------------------
Delphi4Linux Delphi三层/FireDAC 技术群:734515869 http://www.cnblogs.com/rtcmw
作者:
男 crystalmoon (crystalmoon) ★☆☆☆☆ -
盒子活跃会员
2018/5/17 13:13:31
1楼: 全能都发到坛子里来了。。。这个确实不错的,学过Python,R,Go的,应该很能接受的。。切片和通配符。

别外,波哥的QJson今天群里讨论后,也支持了类似查找的功能。
AJson.Match('goods/*/price',[jmsNest,jmsMatchPath]).Match('.+通',[jmsMatchValue])。。。支持ForEach和 for in....大牛们累点,我们用的爽点。按此在新窗口浏览图片
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行62.5毫秒 RSS