`
haoningabc
  • 浏览: 1449180 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

jsonpath的helloworld

阅读更多
基本语法:https://www.cnblogs.com/jpfss/p/10973590.html

这里有个表格,说明JSONPath语法元素和对应XPath元素的对比。
XPath JSONPath Description
/ $ 表示根元素
. @ 当前元素
/ . or [] 子元素
.. n/a 父元素
// .. 递归下降,JSONPath是从E4X借鉴的。
* * 通配符,表示所有的元素
@ n/a 属性访问字符
[] []
子元素操作符
| [,]
连接操作符在XPath 结果合并其它结点集合。JSONP允许name或者数组索引。
n/a [start:end:step]
数组分割操作从ES4借鉴。
[] ?()
应用过滤表示式
n/a ()
脚本表达式,使用在脚本引擎下面。
() n/a Xpath分组



模糊匹配可以用正则:
https://bbs.csdn.net/topics/290047788
or运算用逗号分隔:
https://www.jb51.cc/js/159788.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript JSONPath example | JSON tutorial | w3resource</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://www.w3resource.com/JSON/json.js"></script>
<script type="text/javascript" src="http://www.w3resource.com/JSON/jsonpath.js"></script>
</head>
<body>
<h1>This is an example of JavaScript with JSONPath</h1>
<script type="text/javascript">
               var json = { "MovieDatabase": {
                                            "movie": [ 
                                                       { "name":"nnn",
                                                          "genre": "comedy",
                                                          "director": "teacher",
                                                          "Facebook_like": 252
                                                       },
                                                       {  "name":"helloc",
                                                          "director": "doctor",
                                                          "Facebook_like": 100,
                                                          "movie":{ 
                                                                      "name":"haohao",
                                                                      "genre": "comedy",
                                                                      "director": "killinux",
                                                                      "Facebook_like": 300
                                                                   }
                                                       },
                                                       { "name":"haha",
                                                          "genre": "adventure",
                                                          "director": "Ruben Fleischer",
                                                          "Facebook_like": 114
                                                       }
                                                     ]
                                              }
                          };
               result = "";
               result += jsonPath(json, "$.MovieDatabase.movie[*].director").toJSONString() + "<br />";
               //find all directors
               result += jsonPath(json, "$..director").toJSONString() + "<br />";
               //find all directors
               result += "movie----"+jsonPath(json, "$..movie").toJSONString() + "<br />";
               //find all directors
               result += "*-----"+jsonPath(json, "$.MovieDatabase.*").toJSONString() + "<br />";
               //find all movies
               result += jsonPath(json, "$.MovieDatabase..Facebook_like").toJSONString() + "<br />";
               //find all facebook lies of all the movies
               result += jsonPath(json, "$..movie[(@.length-1)]").toJSONString() + "<br />";
               //the last movie in data
               result += jsonPath(json, "$..movie[-1:]").toJSONString() + "<br />";
               //the last movie in data
               result += jsonPath(json, "$..movie[0,1]").toJSONString() + "<br />";
               //first two movies
               result += jsonPath(json, "$..movie[:3]").toJSONString() + "<br />";
               //first three movies
               result += "genre---"+jsonPath(json, "$..movie[?(@.genre)]").toJSONString() + "<br />";
               //or movies with genre
               result +="Facebook_like----"+ jsonPath(json, "$..movie[?(@.Facebook_like>200)]").toJSONString() + "<br />";
               // condition
               result += "or----"+jsonPath(json, "$..[?(@.name == 'nnn'),?(@.name == 'haohao')]").toJSONString() + "<br />";
               //or
               result += "mohu----"+jsonPath(json, "$..[?(/ha/.test(@.name))]]").toJSONString() + "<br />";
               //fuzzy
               result += "all----"+jsonPath(json, "$..*").toJSONString() + "\n";
               // all members in the JSON document
               document.write(result);
  </script>
  </body>
  </html>

分享到:
评论

相关推荐

    hello world hello world

    hello world

    OpenWrt之helloworld程序

    OpenWrt之helloworld程序开发入门,里面包含helloworld和Makefile

    Helloworld_helloworld_

    输出HELLOWORLD然后输出Helloworld最后的最后的输出Helloworld

    SpringMVC ---- HelloWorld ---- 代码

    SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- Hello...

    HelloWorld_打印HelloWorld_

    打印HelloWorld ,在Visual Studio的开发环境当中,实现简单的操作。

    一个简单的qt版helloworld程序

    一个简单的qt版helloworld程序

    Hello World C源码

    Hello World C源码 Hello World C源码 Hello World C源码 Hello World C源码 Hello World C源码

    helloworld vbs 脚本

    helloworld vbs 脚本hellohelloworld vbs 脚本world vbs 脚本helloworld vbs 脚本helloworld vbs 脚本helloworld vbs 脚本

    Hello World.rar_c++ hello world_world

    c++编写hello world 简单的c++程序

    helloworld.war

    Manning.Struts.2.in.Action 's example HelloWorld.war provides a convenient example of a minimal Struts 2 application

    OCC之HelloWorld.rar

    open cascade hello world open cascade hello world open cascade hello world open cascade hello world open cascade hello world open cascade hello world open cascade hello world open cascade hello world

    深入浅出hello world

    深入浅出hello world。从一个简单的hello,world程序开始,经过预处理、编译、汇编、链接、加载各个步骤详细介绍程序从编辑到执行的过程。深入的讲解了linux下程序的编译过程,并且讲解了linux kernel系统调用的相关...

    helloworld War包测试专用

    helloworld War包,直接上传至服务器webapp目录,自动解压,专用,

    EJB HelloWorld

    HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/remote"); out.println(helloworld.SayHello("佛山人")); 5.用ant或eclipse,把客户端文件打成war包,发布到jboss上 6.输入...

    ssh helloworld小例子

    ssh helloworld小例子 ssh helloworld小例子 ssh helloworld小例子 ssh helloworld小例子 ssh helloworld小例子

    Spring4 HelloWorld

    Spring4 HelloWorld初学Spring,java bean通过applicationContext.xml配置SpringIoC容器生成。

    helloworld程序过程文件

    helloworld.c编译为可执行文件helloworld的过程文件 helloworld.c helloworld.i helloworld.s helloworld.o helloworld

    helloworld

    简单的helloworld程序,适合初学者做实验用,我就是做试验用的

    (1)--HelloWorld

    cocos2d-x初探学习笔记(1)--HelloWorld

    C#入门

    C#第一个程序,helloworld using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace helloworld { class helloworld { [STAThread] static void Main(string[] args)...

Global site tag (gtag.js) - Google Analytics