gpt4 book ai didi

java - 嵌套 json 上的 Karate DSL 断言

转载 作者:行者123 更新时间:2023-11-30 01:57:29 25 4
gpt4 key购买 nike

{"serviceName":"Legal Entity account for given input account.","requestTime":1545426348945,"responseTime":1545426348949,"timeTaken":4,"responseCode":0,"responseMessage":"Success","pageSize":100,"pageNumber":0,"accounts":{"transferDate":1549429200000,"migrationWave":"5","searchedLEAccount":{"accountNumber":"41477514","cbdNumber":"12345678","bic":"CHASGBXxX","poolAccount":"Y","sweepMasterAccount":"Y","status":"DORMANT","branchId":"000000071","branchName":"LONDON","leAccountType":"OLD"},"linkedLEAccount":{"accountNumber":"6541245045","cbdNumber":"854321","bic":"CHASLUY","status":"DORMANT","branchId":"000000055","branchName":"S.A","leAccountType":"NEW"}}}

我正在尝试获取所有 accountNumber 并验证它们是否是数字。我做错了什么?

When method Post

Then status 200

And match response != null

And match response contains {serviceName: 'Legal Entity account for given input account.' }

And match response.accounts.searchedLEAccount contains { accountNumber: '#notnull' }

And match response.accounts.searchedLEAccount contains { accountNumber: '#present' }

And match response.accounts.searchedLEAccount contains { accountNumber: '#number' }

最佳答案

一行:

* match each $..accountNumber == '#regex \\d+'

提示:仔细阅读文档并理解 Json-Path。

这是完整的示例,您可以将其粘贴到新的场景中并查看其工作情况:

* def response = 
"""
{
"serviceName":"Legal Entity account for given input account.",
"requestTime":1545426348945,
"responseTime":1545426348949,
"timeTaken":4,
"responseCode":0,
"responseMessage":"Success",
"pageSize":100,
"pageNumber":0,
"accounts":{
"transferDate":1549429200000,
"migrationWave":"5",
"searchedLEAccount":{
"accountNumber":"41477514",
"cbdNumber":"12345678",
"bic":"CHASGBXxX",
"poolAccount":"Y",
"sweepMasterAccount":"Y",
"status":"DORMANT",
"branchId":"000000071",
"branchName":"LONDON",
"leAccountType":"OLD"
},
"linkedLEAccount":{
"accountNumber":"6541245045",
"cbdNumber":"854321",
"bic":"CHASLUY",
"status":"DORMANT",
"branchId":"000000055",
"branchName":"S.A",
"leAccountType":"NEW"
}
}
}
"""
* match each $..accountNumber == '#regex \\d+'

关于java - 嵌套 json 上的 Karate DSL 断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53892682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com