我正在尝试在json文件中找到一个值,因此我需要获取整个json数据而不是该特定块。
这是我的示例json
[{
"name" : "Redirect to Website 1",
"behaviors" : [ {
"name" : "redirect",
"options" : {
"mobileDefaultChoice" : "DEFAULT",
"destinationProtocol" : "HTTPS",
"destinationHostname" : "SAME_AS_REQUEST",
"responseCode" : 302
}
} ],
"criteria" : [ {
"name" : "requestProtocol",
"options" : {
"value" : "HTTP"
}
} ],
"criteriaMustSatisfy" : "all"
},
{
"name" : "Redirect to Website 2",
"behaviors" : [ {
"name" : "redirect",
"options" : {
"mobileDefaultChoice" : "DEFAULT",
"destinationProtocol" : "HTTPS",
"destinationHostname" : "SAME_AS_REQUEST",
"responseCode" : 301
}
} ],
"criteria" : [ {
"name" : "contentType",
"options" : {
"matchOperator" : "IS_ONE_OF",
"values" : [ "text/html*", "text/css*", "application/x-javascript*" ],
}
} ],
"criteriaMustSatisfy" : "all"
}]
我正在尝试在每个"name" : "redirect"
数组中匹配behaviors
,如果匹配,则需要包括“条件”部分的整个块,如您在同一块{{1 }}
我设法使用选择方法找到值,但无法获取父节。
https://jqplay.org/s/BWJwVdO3Zv
非常感谢您的帮助!
答案 0 :(得分:1)
您可以尝试以下jq命令:
floatingActionButton: new FloatingActionButton(
onPressed: addCard, // pass method reference here
tooltip: 'Add Card',
child: new Icon(Icons.add),
)
答案 1 :(得分:1)
为避免不必要的重复:
.[]
| first(select(.behaviors[].name == "redirect"))
等效地:
.[]
| select(any(.behaviors[]; .name == "redirect"))