Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jmeter的json路径提取器中连接两个json路径查询?_Json_Jmeter_Jsonpath - Fatal编程技术网

如何在jmeter的json路径提取器中连接两个json路径查询?

如何在jmeter的json路径提取器中连接两个json路径查询?,json,jmeter,jsonpath,Json,Jmeter,Jsonpath,假设我有这个流行的数据样本 { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 },

假设我有这个流行的数据样本

{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "color": "red", 
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "color": "blue", 
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}
我想从这里得到的是一本所有的
书籍
where
category==小说
和所有的
自行车
where
color==红色

就是我要,

   {
        "category": "fiction",
        "author": "Evelyn Waugh",
        "color": "red", 
        "title": "Sword of Honour",
        "price": 12.99
    },
    {
        "category": "fiction",
        "author": "Herman Melville",
        "color": "blue", 
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
    },
    {
        "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
    },
    "bicycle": {
         "color": "red",
         "price": 19.95
    }
我知道,我可以使用
$.store.book[?(@.category==“fiction”)]
来实现目标图书,使用
$.store.bicycle[?(@.color==“red”)]
来实现目标自行车


但我怎样才能同时做到这两个呢

您可以使用
&&
|
运算符

$.store.*[?(@.color='red'| |@.category='france')]


将根据需要获取结果

您可以使用
&
|
运算符

$.store.*[?(@.color='red'| |@.category='france')]


将根据需要获取结果

我建议使用和实现您的场景。从过滤数据中提取元素并构建新JSON的示例代码如下所示:

import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

def json = new JsonSlurper().parseText(prev.getResponseDataAsString())

def fictionBooks = json.store.book.findAll {it.category == "fiction"}
def redBikes = json.store.bicycle.findAll{it.color="red"}

JsonBuilder builder = new JsonBuilder(fictionBooks + redBikes)

prev.setResponseData(builder.toPrettyString())
上面的代码将用过滤后的JSON替换父采样器响应数据

参考资料:


我建议使用和实现您的场景。从过滤数据中提取元素并构建新JSON的示例代码如下所示:

import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

def json = new JsonSlurper().parseText(prev.getResponseDataAsString())

def fictionBooks = json.store.book.findAll {it.category == "fiction"}
def redBikes = json.store.bicycle.findAll{it.color="red"}

JsonBuilder builder = new JsonBuilder(fictionBooks + redBikes)

prev.setResponseData(builder.toPrettyString())
上面的代码将用过滤后的JSON替换父采样器响应数据

参考资料:


要归还书籍和自行车,您需要:

$..*[?(@.color== 'red' || @.category == 'fiction')] 
对于颜色==红色或类别==小说的书籍,您需要:

$.store.*[?(@.color== 'red' || @.category == 'fiction')] 

要归还书籍和自行车,您需要:

$..*[?(@.color== 'red' || @.category == 'fiction')] 
对于颜色==红色或类别==小说的书籍,您需要:

$.store.*[?(@.color== 'red' || @.category == 'fiction')] 

我有这个解决方案,但它会在
汽车
自行车
中搜索
颜色
属性和
类别
属性,如果
汽车
颜色
红色
,它也会匹配,但这是不需要的。因此,我想明确检查
自行车的
颜色
是否为
红色
或者
类别
是否为虚构。我有这个解决方案,但是它将在
汽车
自行车
中搜索
颜色
属性和
类别
属性,如果
汽车
颜色
红色
,则也会匹配,但这不是所需的。因此,我想明确检查
自行车的
颜色
红色
还是
类别
是虚构的。这是一个好问题(与jmeter无关)这是一个好问题(与jmeter无关)