0
我有我的JSON:XPath或Defiant.js和獲取節點信息
{
"data": {
"header": {
"version": 1,
"last_updated": "2015-09-16T14:09:22Z"
},
"frequent" : {
"keywords": [
{
"keyword":"roi",
"keyword":"subjectrecord",
"keyword":"evidence",
"keyword":"case",
"keyword":"account",
"keyword":"supervisor",
"keyword":"legacy tecs"
}
]
},
"body": {
"items": [
{
"item": {
"type": "pdf",
"title": "title 1",
"updated_time": "2015-09-16T14:09:22Z",
"keywords": [
{
"keyword":"supervisor"
},
{
"keyword":"manager"
},
{
"keyword":"title 1"
}
]
}
},
{
"item": {
"type": "pdf",
"title": "title 2",
"updated_time": "2015-09-16T14:09:22Z",
"keywords": [
{
"keyword":"supervisor"
}
]
}
},
{
"item": {
"type": "pdf",
"title": "title 3",
"updated_time": "2015-09-16T14:09:22Z"
}
}
]
}
}
}
什麼,我希望能夠做的是搜索「身體」,回到哪裏與之匹配的關鍵字出現的任何項目。因此,舉例來說,如果我搜索「監督員」我的結果應該是這樣的:
"item": {
"type": "pdf",
"title": "title 1",
"updated_time": "2015-09-16T14:09:22Z",
"keywords": [
{
"keyword":"supervisor"
},
{
"keyword":"manager"
},
{
"keyword":"title 1"
}
]
}
},
{
"item": {
"type": "pdf",
"title": "title 2",
"updated_time": "2015-09-16T14:09:22Z",
"keywords": [
{
"keyword":"supervisor"
}
]
}
}
執行以下操作,只返回關鍵字。
var results = JSON.search(potentials, '//*[keyword="'+query+'"]');