1 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊
我不確定是否理解你的問題,如果你正在尋找一個(gè) jsonpath 過濾器來獲取與該字段關(guān)聯(lián)的值"name": "Subject",這通常應(yīng)該有效:
"payload.headers[?(@.name=='Subject')].value"
但我看了一下json-path rest-assured,這是 Serenity rest 用來執(zhí)行 json-path 操作的庫,該庫不使用標(biāo)準(zhǔn)的 json-path synthax,而是使用基于 groovy lambda 的 synthax 來執(zhí)行高級搜索。所以這應(yīng)該有效:
"headers.find{ it.name == 'Subject' }.value"
我用一個(gè)完整的例子來測試:
JsonPath.from("{\"payload\": {\n" +
" \"mimeType\": \"multipart/alternative\",\n" +
" \"headers\": [\n" +
" {\n" +
" \"name\": \"Mime-Version\",\n" +
" \"value\": \"1.0\"\n" +
" },\n" +
" {\n" +
" \"name\": \"Subject\",\n" +
" \"value\": \"Welcome!\"\n" +
" },\n" +
" {\n" +
" \"name\": \"To\",\n" +
" \"value\": \"Jane Doe <xyz@xyz.com>\"\n" +
" },\n" +
" {\n" +
" \"name\": \"Message-ID\",\n" +
" \"value\": \"<123456.abc.com>\"\n" +
" }\n" +
" ]\n" +
"}}")
.getString("headers.find{ it.name == 'Subject' }.value");
// returns "Welcome!"
添加回答
舉報(bào)