0

假设我从 API 调用中得到以下响应。

accounts: [

accountName: "A",
amount: 10$

account Name "B closed",
amount: 20$

]

我想过滤帐户名称中包含已关闭关键字的所有帐户响应。谁能告诉我如何根据此过滤所有包含已关闭的响应并只给我帐户 A。

我将 dw 1.0 用于我的 mulesoft 代码。如果您有任何其他问题,请告诉我。

4

1 回答 1

3

假设您的输入是:

{
  "accounts": [
    {
      "accountName": "A",
      "amount": "10$"
    },
    {
      "accountName": "B closed",
      "amount": "20$"
    }
  ]
}

然后你可以像这样过滤它:

%dw 1.0
%output application/json
---
payload.accounts filter ((account) -> not (account.accountName contains "closed"))

这将导致:

[
  {
    "accountName": "A",
    "amount": "10$"
  }
]
于 2019-03-26T14:52:20.917 回答