SharePoint REST OData 查询 - 标题有大括号,如何检索



我有一个简单的列表,它有一个标题字段。 该"标题"字段中的某些值具有大括号。 例如"客户端{以前称为其他内容}">

我正在尝试使用 OData 检索此记录。 这是我的查询:

https://xxx.sharepoint.com/forms/_api/web/lists/getbytitle('client'(/items?$select=ID,Title&$filter=Title%20eq%20%27Client%20%7BFormally%20known%20as%20Something%20else%7D%27

我也试过

https://xxx.sharepoint.com/forms/_api/web/lists/getbytitle('clients'(/items?$select=ID,Title&$filter=Title%20eq%20%27Client%20{Formally%20known%20as%20Something%20else}%27

我没有返回任何记录。 当我在过滤器中输入一个简单的值时,它工作正常。 那么我该如何转义或处理大括号呢?

根据我的测试,这可能是 URL 编码问题。您可以仔细检查您的网址字符串。 根据您的描述,我尝试在图形提供的 API 端点上使用 {},这很好,没有编码问题。

以下是我请求的网址:

https://graph.microsoft.com/v1.0/users?$filter=startswith(givenName,'{1222}')

这是我的响应数据

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
"value": [
{
"id": "f4d2e619-43b9-40f1-b926-78696ccf976e",
"businessPhones": [],
"displayName": "{1222}",
"givenName": "{1222}",
"jobTitle": null,
"mail": "",
"mobilePhone": null,
"officeLocation": null,
"preferredLanguage": null,
"surname": null,
"userPrincipalName": ""
}
]
}

您可以将这些特殊字符编码为 Unicode,并使用 % 符号进行转义。见下文。

检索标题字段值为以下项:客户端 {卷曲中的文本} API 调用:/_api/lists/getbytitle('Sample'(/items?$filter=Title eq 'Client %u007BText in Curlys%u007D'

这是一个关于堆栈溢出的相关问题

希望对您有所帮助!

最新更新