Leo*_*eon 7 json jsonp jsonpath
基本上,我需要使用 JSONPath 获取字符串值的一部分。我无法先使用 JSONPath 获取完整值,然后使用另一种语言获取它的一部分。
有没有办法在 JSONPath 中做到这一点?
如果您能举例说明一些 JSON 数据,那就太好了。根据您所写的内容,我怀疑您正在寻找类似的东西(这里是 JSFilddle: http: //jsfiddle.net/hbi99/4WYkc/);
var data = {
"store": {
"book": [
{
"@price": 12.99,
"title": "Sword of Honour",
"category": "fiction",
"author": "Evelyn Waugh"
},
{
"@price": 22.99,
"title": "The Lord of the Rings",
"category": "fiction",
"author": "J. R. R. Tolkien",
"isbn": "0-395-19395-8"
}
],
"bicycle": {
"@price": 19.95,
"brand": "Cannondale",
"color": "red"
}
}
},
found = JSON.search(data, '//*[contains(title, "Lord")]');
document.getElementById('output').innerHTML = found[0].title;
Run Code Online (Sandbox Code Playgroud)
JSONPath 不是标准化的“查询语言”,但 XPath 是。JS 库 DefiantJS 通过“search”方法扩展了全局对象 JSON,通过该方法可以使用 XPath 表达式查询 JSON 结构。该方法将匹配项作为类似数组的对象返回。
要查看更多示例,请在此处查看实时 XPath Evaluator: http: //defiantjs.com/#xpath_evaluator
| 归档时间: |
|
| 查看次数: |
4081 次 |
| 最近记录: |