C# JSON编译请求的文件或其依赖项时出错;预期

C# JSON编译请求的文件或其依赖项时出错;预期,c#,json,sharepoint,formatting,C#,Json,Sharepoint,Formatting,我正在尝试格式化此JSON,以便能够正确地将其分配给DataProviderJSON。 它不断给我一个变量“测试”的错误: 编译请求的文件或其依赖项时出错;期望 更新:现在它似乎是工作,但我得到了一个新的错误 box.DataProviderJSON=测试 引发了类型为“System.Web.HttpUnhandledException”的异常。-->System.ArgumentException:传入的对象无效,应为“:”或“}” 这是JSON: "{\"QueryGroupName\":\

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

编译请求的文件或其依赖项时出错;期望

更新:现在它似乎是工作,但我得到了一个新的错误

box.DataProviderJSON=测试

引发了类型为“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[...]";

谢谢,成功了;现在在box.DataProviderJSON=testing上给我这个错误:抛出了类型为“System.Web.HttpUnhandledException”的异常。-->System.ArgumentException:传入的对象无效,应为“:”或“}”。请在测试中检查PropertiesJson属性。您希望像为属性指定值一样指定JSON对象,但将该对象放在双引号中,这就是为什么它被解释为字符串。因此,您分配字符串{到您的属性JSON,而不是整个对象,由于语法错误,无法解析对象的其余部分。如果删除双引号不能解决问题,请尝试删除JSON中的所有属性,并检查它是否引发任何错误-然后逐个添加属性,以查看是哪一个导致错误。您好,我是able试图通过调试检索JSON,我使用Jsonvalidator注意到它的格式不好。现在JSON很好,我在DataProviderJSON上遇到了一个问题。反序列化数组时不支持类型“System.String”。这可能是因为您正试图从[]注释的JSON对象转换数组在代码中的字符串变量中,可能不是字符串数组string[]?是的,我需要将该JSON分配给DataProviderJson属性:,它是一个字符串。我如何才能做到这一点?
testing = "[...]\"QueryPropertiesTemplateUrl\":\"\",\"IgnoreQueryPropertiesTemplateUrl[...]";