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

时间:2018-08-23 00:09:12

标签: rest sharepoint odata

我有一个简单的列表,其中包含标题字段。该“标题”字段中的某些值带有大括号。例如“客户{以前称为Something}}

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

https://xxx.sharepoint.com/forms/_api/web/lists/getbytitle(“客户”)/项目?$ 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 {Formal%20known%20as%20Something%20else}%27

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

2 个答案:

答案 0 :(得分:0)

根据我的测试,可能是网址编码问题。您可以仔细检查您的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": ""
        }
    ]
}

答案 1 :(得分:0)

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

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

Here’s a related question on Stack Overflow

希望有帮助!