2 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊
Rest Assured 使用 Groovy 的 Gpath。因此,您的查詢(xún)可能如下所示:
JsonPath pathToAccountName = response.jsonPath();
String value = jsonPath.getString("fields.find { it.fieldId == 'individualName' }.value");
在這里您可以找到一些示例(它是關(guān)于處理 XML,但也適用于 JSON): http: //groovy-lang.org/processing-xml.html

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊
我需要知道如何獲得這個(gè)輸出 -
JSON 文檔 -{ "status": "E000", "customerId": "VjAxI2VhNzg5ZmJlLWIyNjAtNGZlOS1iZDNkLTdjMmU1MjA2ZmVhZA", "merchantId": "1", "cards": [ { "cardType": "DEBIT", "cardIssuer": "AXIS", "cardBrand": "MASTERCARD", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null }, { "cardType": "CREDIT", "cardIssuer": "ICICI Bank", "cardBrand": "MASTERCARD", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null }, { "cardType": "CREDIT", "cardIssuer": "HDFC Bank", "cardBrand": "MASTERCARD", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null }, { "cardType": "CREDIT", "cardIssuer": "ICICI Bank", "cardBrand": "VISA", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null }, { "cardType": "DEBIT", "cardIssuer": "Punjab National Bank", "cardBrand": "MASTERCARD", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null }, { "cardType": "CREDIT", "cardIssuer": "ICICI Bank", "cardBrand": "MASTERCARD", "nickName": null, "expired": null, "cardMigrationStatus": "DONE", "tur": null, "category": null } ], "status_mssg": null }
我想要這個(gè)輸出 - [ { "cardType": "DEBIT", "cardIssuer": "AXIS", "cardBrand": "MASTERCARD", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null }, { "cardType": "CREDIT", "cardIssuer": "ICICI Bank", "cardBrand": "MASTERCARD", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null }, { "cardType": "CREDIT", "cardIssuer": "HDFC Bank", "cardBrand": "MASTERCARD", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null }, { "cardType": "DEBIT", "cardIssuer": "Punjab National Bank", "cardBrand": "MASTERCARD", "nickName": "", "expired": "false", "cardMigrationStatus": "OPEN", "tur": null, "category": null } ]
我正在使用這個(gè) - jsonPathValidator.getString("$.cards[?(@.cardMigrationStatus == 'OPEN' && @.cardBrand == 'MASTERCARD')]");
但沒(méi)有得到輸出。
添加回答
舉報(bào)