<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":"The Change-Up",
"genre": "comedy",
"director": "David Dobkin",
"Facebook_like": 252
},
{ "name":"Rise of the Planet of the Apes",
"genre": "SciFi",
"director": "Rupert Wyatt",
"Facebook_like": 472
},
{ "name":"30 Minutes or Less",
"genre": "adventure",
"director": "Ruben Fleischer",
"Facebook_like": 114
},
{ "name":"Final Destination 5",
"genre": "Horror",
"director": "Steven Quale",
"Facebook_like": 241
}
]
}
};
result = "";
result += jsonPath(json, "$.MovieDatabase.movie[*].director").toJSONString() + "<br />";
//find all directors
result += jsonPath(json, "$..director").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 += jsonPath(json, "$..movie[?(@.genre)]").toJSONString() + "<br />";
//all movies with genre
result += jsonPath(json, "$..movie[?(@.Facebook_like>200)]").toJSONString() + "<br />";
//movies with facebook like more that 200
result += jsonPath(json, "$..*").toJSONString() + "\n";
// all members in the JSON document
document.write(result);
</script>
</body>
</html>

JavaScript with JSONPath的更多相关文章

  1. javascript: Jquery each loop with json array or object

    http://www.codeproject.com/Articles/779303/JSON-and-Microsoft-technologies http://www.codeproject.co ...

  2. 好用的json-path

    $.store.book[?(@.price < 10)].title Here is a complete overview and a side by side comparison of ...

  3. JsonPath详解

    JsonPath is to JSON what XPATH is to XML, a simple way to extract parts of a given document. JsonPat ...

  4. Python爬虫(十六)_JSON模块与JsonPath

    本篇将介绍使用,更多内容请参考:Python学习指南 数据提取之JSON与JsonPATH JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,它是的人们很容易 ...

  5. python中jsonpath模块的运用

    1. jsonpath介绍用来解析多层嵌套的json数据;JsonPath 是一种信息抽取类库,是从JSON文档中抽取指定信息的工具,提供多种语言实现版本,包括:Javascript, Python, ...

  6. Jsonpath的基本使用

    JSONPath - 是xpath在json的应用. xml最大的优点就有大量的工具可以分析,转换,和选择性的提取文档中的数据.XPath是这些最强大的工具之一.   如果可以使用xpath来解析js ...

  7. 9.json和jsonpath

    数据提取之JSON与JsonPATH JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写.同时也方便了机器进行解析和生成.适 ...

  8. JSONPath使用说明

    # JSONPath - XPath for JSON A frequently emphasized advantage of XML is the availability of plenty t ...

  9. JsonPath小结

    在查看DHC Assertions 模块说明的时候,无意间发现assert模块中JsonBody使用了 JSON Path ,兴趣使然,看了下,发现是类似解析xml用到的 XPath.通过路径来获取j ...

随机推荐

  1. LightOJ 1088 - Points in Segments 二分

    http://www.lightoj.com/volume_showproblem.php?problem=1088 题意:给出N个点,Q个查询,问在区间内的点数有多少个. 思路:直接在线二分,注意边 ...

  2. 重构改善既有代码设计--重构手法11:Move Field (搬移字段)

    你的程序中,某个字段被其所驻类之外的另一个类更多的用到.在目标类建立一个新字段,修改源字段的所有用户,令它们改用新字段.        动机:在类之间移动状态和行为,是重构过程中必不可少的措施.随着系 ...

  3. MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields

    Different query operators in MongoDB treat null values differently. The examples on this page use th ...

  4. .net core 中 identity server 4 之术语

    id4的职责: 保护你的资源 通过本地 账户库(Account Store)或者外部身份提供其 认证用户 提供Session管理以及SSO 管理和认证客户端 发行身份及访问Token给客户端 验证To ...

  5. 【CodeForces】908 D. New Year and Arbitrary Arrangement

    [题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符 ...

  6. 2017ACM暑期多校联合训练 - Team 1 1011 HDU 6043 KazaQ's Socks (找规律)

    题目链接 Problem Description KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbe ...

  7. NYOJ 221 Tree (二叉树)

    题目链接 描述 Little Valentine liked playing with binary trees very much. Her favorite game was constructi ...

  8. Linux命令学习手册-route命令

    route [-CFvnee] route [-v]  [-A family] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss ...

  9. Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070058 android-studio 3.0 from canary 5 to canary 6

    我升级android-studio到了3.0 canary 6打包编译安装出现如下错误: 07-11 13:00:39.523 8913-8913/dcpl.com.myapplication E/A ...

  10. Struts2使用

    Struts2是一个基于MVC设计模式的Web应用框架.在MVC设计模式中,Struts2作为控制器(Controller)来建立模型与视图的数据交互.Struts 2是Struts的下一代产品,是在 ...