英文:
JSONPath get value from map within a table
问题
{
"data":{
"fruit":[
{
"role":[
{
"role":"passive"
}
],
"objectType":"apple"
},
{
"role":[
{
"role":"active"
}
],
"objectType":"orange"
}
]
}
}
我想要在 role 为 active 的情况下获取 objectType 的值。在这个例子中,结果将是 orange。我已经想出了以下代码,但是它没有返回任何内容。我该如何修复这个问题?
$.data.fruit[?(@.role[0].role == 'active')].objectType
请注意,fruit 数组中的元素数量可能会变化,并且不能保证最后一个元素是正确的。
英文:
I have a JSON string as follows (simplified):
{
"data":{
"fruit":[
{
"role":[
{
"role":"passive"
}
],
"objectType":"apple"
},
{
"role":[
{
"role":"active"
}
],
"objectType":"orange"
}
]
}
}
I would like to get objectType value where role is active. In this example the result would be orange. I've come up with the following code, however it doesn't return anything. How do I fix this?
$.data.fruit[?(@.role.role == 'active')]
Note that the number of elements in fruit array may vary and there is no guarantee that the last element would be correct.
答案1
得分: 0
根据OP的要求,这是最终的最终答案!
$.data.fruit[?(@..role..role中存在'active')].objectType
英文:
At OP's request, here's the final, final answer!
$.data.fruit[?('active' in @..role..role)].objectType
答案2
得分: -2
在这种情况下,如果它是一个数字,在字符串化的每个递进级别将缩进这么多空格字符(最多10个)。
如果它是一个字符串,递进级别将被这个字符串缩进(或其前面的十个字符)。
英文:
On the off chance that it is a number, progressive levels in the stringification will each be indented by this many space characters (up to 10).
In the event that it is a string, progressive levels will be indented by this string (or its initial ten characters).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论