【发布时间】:2019-03-02 03:02:07
【问题描述】:
我试图在 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"
}]
我正在尝试在每个 behaviors 数组中匹配 "name" : "redirect",如果匹配,那么我需要包括“条件”部分在内的整个块,因为您可以在同一块 {} 下看到它
我设法使用选择方法找到了值,但无法获取父部分。
https://jqplay.org/s/BWJwVdO3Zv
非常感谢任何帮助!
【问题讨论】:
-
对于给定的示例,包括“标准”部分的整个块会选择所有内容,对吗?如果没有,请使用预期输出更新您的问题。
-
@oliv 使用当前设置我无法过滤它。它正在返回整个 json 文件。