我作为API响应低于JSON
。我想断言是否存在这5个关键值
"
"DayClosingDate": "/Date(-62135596800000)/",
"StartTime": "/Date(-62135596800000)/",
"EndTime": "/Date(-62135596800000)/",
"OpeningBalance": 0,
"CashAmount": 0,
"CreditCardAmount": 0,
"
什么应该是最好的断言?
{
"d": {
"__type": "WSOffline.Response",
"Status": "0",
"Message": "Success",
"Data": [
{
"DayClosingID": 26030,
"UID": 0,
"StoreID": 0,
"CashRegisterID": 0,
"DayClosingDate": "/Date(-62135596800000)/",
"StartTime": "/Date(-62135596800000)/",
"EndTime": "/Date(-62135596800000)/",
"OpeningBalance": 0,
"CashAmount": 0,
"CreditCardAmount": 0,
"OtherAmount": 0,
"BalanceAmount": 0,
"Remarks": null,
"CreatedByEmployeeID": 0,
"CreatedDatetime": "/Date(-62135596800000)/",
"ClosingDoneByEmployeeID": 0,
"ClosingDoneDateTime": "/Date(-62135596800000)/",
"PaymentDetails": [],
"StartTimeText": null,
"EndTimeText": null,
"CashRegisterName": null,
"DayClosingDateText": null,
"InvoiceName": null,
"InvoiceDate": null,
"StoreName": null,
"CreatedByEmployee": null,
"ClosingDoneByEmployee": null,
"DayClosingDone": null
}
]
}
}
答案 0 :(得分:0)
取决于值是否为动态值。是吗? 如果没有,您可以轻松地将以下行放入响应断言中,匹配规则为“包含”。
“DayClosingDate”:“/日期(-62135596800000)/”
您可以针对您需要的每个断言单独执行此操作。您也可以根据需要选择jp @ gc - JSON Path Assertion插件。
答案 1 :(得分:0)
如果您只想验证参数名称,那么 断言:JSONpath存在匹配 这将是你的jsonpath表达式:
$..DayClosingDate
结果:如果存在,则为真。
或者如果你想验证参数值,那么 断言:JSONpath匹配 这将是你的jsonpath表达式:
$..DayClosingDate
结果:/日期(-62135596800000)/