Groovy 提取profileId的列表';s使用jsonpath
我有以下JSON对象Groovy 提取profileId的列表';s使用jsonpath,groovy,jsonpath,Groovy,Jsonpath,我有以下JSON对象r2 [ { "reserva_id":"200", "estancias":[ { "reserva_estancia":"266", "huespedes":[ { "reserva_
r2
[
{
"reserva_id":"200",
"estancias":[
{
"reserva_estancia":"266",
"huespedes":[
{
"reserva_huesped":"272",
"reserva_estancia":"266",
"numero_huesped":"1",
"huesped":"123",
"huesped_nombre":"dos dos, dos",
"rfid":null
},
{
"reserva_huesped":"276",
"reserva_estancia":"266",
"numero_huesped":"2",
"huesped":"183",
"huesped_nombre":"MUESTRA MUESTRA, CARMEN",
"rfid":null
}
]
}
]
},
{
"reserva_id":"201",
"estancias":[
{
"huespedes":[
{
"reserva_huesped":"273",
"reserva_estancia":"267",
"numero_huesped":"1",
"huesped":"148",
"huesped_nombre":"MUESTRA MUESTRA, CARMEN",
"rfid":null
},
{
"reserva_huesped":"277",
"reserva_estancia":"267",
"numero_huesped":"2",
"huesped":"187",
"huesped_nombre":"TEST TEST, TESTCIVITFUN",
"rfid":null
}
]
}
]
}
]
我试图为每个预订获取第一个huesped
,为此,我使用以下脚本创建一个名为profiles的列表并存储profileId:
def profiles = jsonpath(r2,'$..[:].estancias[:].huespedes[0].huesped')
输出应如下所示:
[
"123",
"148"
]
但是,当我打印
profiles.text
时,我会得到estancias
对象的所有内容,而不仅仅是huesped
编号。像这样使用Jayway的JSONPath时,我会得到所需的oputput:
$..[*].estancias[*].huespedes[0].huesped
您可以用JSON尝试路径表达式。在哪里使用它?JMeter,SoapUI?由于我不了解您的环境,因此无法添加进一步的说明。