繁体   English   中英

JSON编译请求的文件或其依赖项之一时发生错误。 ; 预期

[英]JSON An error occurred during the compilation of the requested file, or one of its dependencies. ; expected

我正在尝试格式化此JSON,以便能够将其正确分配给DataProviderJSON。 它不断给我一个关于变量“测试”的错误:

编译请求的文件或其依赖项之一时发生错误。 ; 预期

 using (ContentBySearchWebPart box = GetControlByIDPath(ControlID, this.Page.Controls[0]) as ContentBySearchWebPart)
    {
                    string testing;
                    testing = "{\"QueryGroupName\":\"Default\",\"QueryPropertiesTemplateUrl\":"",\"IgnoreQueryPropertiesTemplateUrl\":false,\"SourceID\":\"8413cd39-2156-4e00-b54d-11efd9abdb89\",\"SourceName\":\"Local SharePoint Results\",\"SourceLevel\":\"Ssa\",\"CollapseSpecification\":"",\"QueryTemplate\":\"#test (ContentTypeId:0x01FD4FB0210AB50249908EAA47E6BD3CFE8B* OR ContentTypeId:0x01FD59A0DF25F1E14AB882D2C87D4874CF84* OR ContentTypeId:0x012002* OR ContentTypeId:0x0107* OR WebTemplate=COMMUNITY)\",\"FallbackSort\":[],\"FallbackSortJson\":[],\"RankRules\":[],\"RankRulesJson\":\"[]\",\"AsynchronousResultRetrieval\":false,\"SendContentBeforeQuery\":true,\"BatchClientQuery\":true,\"FallbackLanguage\":-1,\"FallbackRankingModelID\":\"\",\"EnableStemming\":true,\"EnablePhonetic\":false,\"EnableNicknames\":false,\"EnableInterleaving\":false,\"EnableQueryRules\":true,\"EnableOrderingHitHighlightedProperty\":false,\"HitHighlightedMultivaluePropertyLimit\":-1,\"IgnoreContextualScope\":true,\"ScopeResultsToCurrentSite\":false,\"TrimDuplicates\":false,\"Properties\":{\"TryCache\":true,\"Scope\":\"{Site.URL}\",\"UpdateLinksForCatalogItems\":true,\"EnableStacking\":true,\"ListId\":\"8837b1d4-c29a-4ab0-9385-f483c19b25ec\",\"ListItemId\":4},\"PropertiesJson\":\"{\"TryCache\":true,\"Scope\":\"{Site.URL}\",\"UpdateLinksForCatalogItems\":true,\"EnableStacking\":true,\"ListId\":\"8837b1d4-c29a-4ab0-9385-f483c19b25ec\",\"ListItemId\":4}\",\"ClientType\":\"ContentSearchRegular\",\"UpdateAjaxNavigate\":true,\"SummaryLength\":180,\"DesiredSnippetLength\":90,\"PersonalizedQuery\":false,\"FallbackRefinementFilters\":null,\"IgnoreStaleServerQuery\":false,\"RenderTemplateId\":\"DefaultDataProvider\",\"AlternateErrorMessage\":null,\"Title\":""}";
                    box.DataProviderJSON = testing; }

更新:现在好像正在工作,但是我遇到了一个新的错误

box.DataProviderJSON = testing;

引发了类型为'System.Web.HttpUnhandledException'的异常。 ---> System.ArgumentException:传入无效的对象,应为':'或'}'。

这是JSON:

"{\"QueryGroupName\":\"Default\",\"QueryPropertiesTemplateUrl\":\"\",\"IgnoreQueryPropertiesTemplateUrl\":false,\"SourceID\":\"8413cd39-2156-4e00-b54d-11efd9abdb89\",\"SourceName\":\"Local SharePoint Results\",\"SourceLevel\":\"Ssa\",\"CollapseSpecification\":\"\",\"QueryTemplate\":\"#test(ContentTypeId:0x01FD4FB0210AB50249908EAA47E6BD3CFE8B* OR ContentTypeId:0x01FD59A0DF25F1E14AB882D2C87D4874CF84* OR ContentTypeId:0x012002* OR ContentTypeId:0x0107* OR WebTemplate=COMMUNITY)  \",\"FallbackSort\":[],\"FallbackSortJson\":[],\"RankRules\":[],\"RankRulesJson\":\"[]\",\"AsynchronousResultRetrieval\":false,\"SendContentBeforeQuery\":true,\"BatchClientQuery\":true,\"FallbackLanguage\":-1,\"FallbackRankingModelID\":\"\",\"EnableStemming\":true,\"EnablePhonetic\":false,\"EnableNicknames\":false,\"EnableInterleaving\":false,\"EnableQueryRules\":true,\"EnableOrderingHitHighlightedProperty\":false,\"HitHighlightedMultivaluePropertyLimit\":-1,\"IgnoreContextualScope\":true,\"ScopeResultsToCurrentSite\":false,\"TrimDuplicates\":false,\"Properties\":{\"TryCache\":true,\"Scope\":\"Site.URL\",\"UpdateLinksForCatalogItems\":true,\"EnableStacking\":true,\"ListId\":\"8837b1d4-c29a-4ab0-9385-f483c19b25ec\",\"ListItemId\":4},\"PropertiesJson\":{\"TryCache\":true,\"Scope\":\"{Site.URL}\",\"UpdateLinksForCatalogItems\":true,\"EnableStacking\":true,\"ListId\":\"8837b1d4-c29a-4ab0-9385-f483c19b25ec\",\"ListItemId\":4},\"ClientType\":\"ContentSearchRegular\",\"UpdateAjaxNavigate\":true,\"SummaryLength\":180,\"DesiredSnippetLength\":90,\"PersonalizedQuery\":false,\"FallbackRefinementFilters\":null,\"IgnoreStaleServerQuery\":false,\"RenderTemplateId\":\"DefaultDataProvider\",\"AlternateErrorMessage\":null,\"Title\":\"\"}";

您没有在QueryPropertiesTemplateUrl之后转义" 。”因此,该字符串在此处结束,并且编译器缺少;来结束该语句。

testing = "{\"QueryGroupName\":\"Default\",\"QueryPropertiesTemplateUrl\":" //; The string ends, but is not followed by an semicolon - thus the compile error. 

您宁愿使用

testing = "[...]\"QueryPropertiesTemplateUrl\":\"\",\"IgnoreQueryPropertiesTemplateUrl[...]";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM