<p>我相信你在JSON中遗漏了一个逗号:</p>
<pre><code>{
"user":
{
"actions": [
{
"name": "reading",
"description": "blablabla"
}
],
"name": "John"
}
}
</code></pre>
<p>假设只有一个“John”,只有一个“reading”活动,则以下查询有效:</p>
<pre><code>$.user[@.name is 'John'].actions[0][@.name is 'reading'][0].description
</code></pre>
<hr/>
<p>如果可能有多个“John”s和多个“reading”活动,则以下查询几乎可以工作:</p>
<pre><code>$.user.*[@.name is 'John'].actions..*[@.name is 'reading'].description
</code></pre>
<p>我说<strong>几乎是</strong>,因为如果有其他嵌套字典包含“name”和“description”条目,比如</p>
<pre><code>{
"user": {
"actions": [
{
"name": "reading",
"description": "blablabla",
"nested": {
"name": "reading",
"description": "broken"
}
}
],
"name": "John"
}
}
</code></pre>
<p>要获得正确的查询,需要正确地将查询实现到数组中,<a href="https://github.com/adriank/ObjectPath/issues/60" rel="nofollow noreferrer">https://github.com/adriank/ObjectPath/issues/60</a></p>