跳到主要内容

筛选数据

你可以使用 Flows 查询语言 (FQL) 过滤响应中的特定数据。多个响应返回一个数组。单个响应作为单个记录返回。示例数据和 FQL 示例如下。

示例 JSON

下面的示例使用此 JSON 数据:

{
"customer info": {
"customer field": "Customer data",
"unformated_customer_field": " customer \n stuff ",
"total_value": "281.01",
"associated_usernames": ["user1, myuser, online_user"]
},
"payments": [
{
"invoice_number": "101301",
"date": "2022-09-11T16:12:34.494Z",
"description": "recurring subscription",
"amount": 110.48
},
{
"invoice_number": "101302",
"date": "2022-09-29T14:45:13.148Z",
"description": "one time purchase",
"amount": 24.49
},
{
"invoice_number": "101303",
"date": "2022-10-11T16:12:34.683Z",
"description": "recurring subscription",
"amount": 110.48
},
{
"invoice_number": "101304",
"date": "2022-10-12T11:45:22.182Z",
"description": "recurring subscription deluxe",
"amount": 35.56
}
]
}

过滤具有特定键值对的对象的查询结果

下面的示例过滤payments数组中具有键值对的对象"description": "recurring subscription"

FQLpayments[description="recurring subscription"]
Result
[ { "invoice_number": "101301", "date": "2022-09-11T16:12:34.494Z", "description": "recurring subscription", "amount": 110.48 }, { "invoice_number": "101303", "date": "2022-10-11T16:12:34.683Z", "description": "recurring subscription", "amount": 110.48 } ]

浏览过滤后的结果

FQL 使用与导航 JSON 数据相同的语法来导航筛选的查询结果。invoice.number下面的示例从数组中的字段中获取值payments

FQLpayments[description="recurring subscription"].invoice_number
Result["101301","101303"]

返回单条记录

当过滤器有单个结果时,它作为记录而不是数组返回。下面的过滤器返回单个结果作为记录。

普通话payments[description="定期订阅豪华版"].invoice_number
结果[“101304”]

检查字段是否具有特定值

FQL 可以检查你的查询结果是否具有特定的键值对并返回trueor false。下面的示例检查数组中的第一项payments以查找键值对"description": "recurring"

FQL$contains(payments[0].description, "recurring")
Resulttrue

仅获取唯一的付款金额

$distinct函数返回任何重复值的单个实例。在下面的示例中,该110.48值在数据中出现了两次,但在结果中只出现了一次。

FQL$distinct(payments.amount)
Result[110.48, 24.49, 35.56]