我有以下代码段。随Xamarin Sitecore扩展提供的示例代码的略微修改版本。
var requesttwo = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("select * from /sitecore/content/Home//*[@@TemplateName='Article']")
.AddFieldsToRead(new string[3] { "Title", "Author", "Content" })
.AddScope(ScopeType.Self)
.Build();
ScItemsResponse response = null;
try
{
// And execute it on a session asynchronously
response = await session.ReadItemAsync(requesttwo);
}
catch (Exception e)
{
String error = e.Message;
}
当我替换
时,它按预期工作ReadItemsRequestWithSitecoreQuery("select * from /sitecore/content/Home//*[@@TemplateName='Article']")
带
ReadItemsRequestWithPath("/sitecore/content/home")
但上面的块抛出“来自互联网的[Sitecore Mobile SDK]数据具有意外格式。”我发现this question并且我确实认识到sitecore查询使用“@”但我添加了下面的代码段,因为它似乎建议我得到相同的响应。
string format = HttpUtility.HtmlEncode("select * from /sitecore/content/Home//*[@@TemplateName='Article']");
答案 0 :(得分:0)
我弄明白了这个问题。以下代码按预期工作。
var requesttwo = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/Home//*[@@TemplateName='Article']")
.AddFieldsToRead(new string[3] { "Title", "Author", "Content" })
.Build();
ScItemsResponse response = null;
try
{
// And execute it on a session asynchronously
response = await session.ReadItemAsync(requesttwo);
}
catch (Exception e)
{
String error = e.Message;
}
我只需要从"中删除" select *。我想AddFieldsToRead正在附加它自己的select语句,它正在发出请求"从select * from"中选择foo bar。或类似的东西。只是从查询中删除该部分就可以得到正确的响应。
线索在this document。底部示例仅显示sitecore路径,而不是完整查询。
string query = "/sitecore/media library/images/*";
var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(query)
.AddScope(ScopeType.Self)
.PageNumber(0)
.ItemsPerPage(2)
.Build();
var response = await this.session.ReadItemAsync(request);