我有2个JSON数组
a= [{"[{ "Id": "123","Types": "Dial"},{"Id": "963", "Types": "Post"},{"Id": "456","Types": "Dial"},
{ "Id": "569","Types": "Dial"}]
b= [{"Subject": {"Prog": [{"Type": "Identifier","Id": "123"}]}},
{"Subject": {"Prog": [{"Type": "Identifier" ,"Id": "569"}]}},
{"Subject": {"Prog": [{"Type": null,"Id": "963"}]}},
{"Subject": {"Prog": [{"Type": null,"Id": "963"}]}},
{"Subject": {"Prog": [{"Type": null,"Id": "963"}]}},
{"Subject": {"Prog": [{"Type": null,"Id": "963"}]}},
{"Subject": {"Prog": [{"Type": "Identifier","Id": "456"}]}}]
我想从"a"验证";类型";值为"0";POST";,对于相应的";id";在JSON中";b"类型";具有值";空";
请帮忙。
您可以通过使用Json路径集成和空手道来实现这一点,也可以使用过滤器功能。
* def IdArray = karate.jsonPath(a,"$..[?(@.Types=="Post")].Id")
* def FilteredArray = call FilterFunction(IdArray,b)
您可以将过滤功能定义为
* def FilterFunction =
"""
function(arr,b)
{ var result = []
for(i=0;i<arr.length;i++)
{ var Mypath = "$..[?(@.Id==""+ arr[i] +"")].Type"
var newArr = karate.jsonPath(b,Mypath)
karate.apend(result,newArr)
}
return result
}
""""
这样filteredArray将包含所有空值。只需对该数组应用空值检查即可。