RestAssured JsonPath:从 json 获取数据时出现问题?

RestAssured JsonPath: Issue with getting data from json?

我需要知道如何获得这个输出 -

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 }

我想要这个输出 -

[ { "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 } ]

我正在使用这个 -

jsonPathValidator.getString("$.cards[?(@.cardMigrationStatus == 'OPEN' && @.cardBrand == 'MASTERCARD')]");

但没有得到输出。

试试这个

var result = jsonPath(json, "$.cards[?(@.cardMigrationStatus == 'OPEN' && @.cardBrand == 'MASTERCARD')]");

结果

[
  {
    "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
  }
]

不,它使用 GPath 提取值,而不是 jayway jsonpath。

语法:

.getString("cards.findAll {it.cardMigrationStatus == 'OPEN' && it.cardBrand == 'MASTERCARD'}");

.getList("cards.findAll {it.cardMigrationStatus == 'OPEN' && it.cardBrand == 'MASTERCARD'}");