眼前的问题在处理使用Json.NET的不同库时遇到此问题。在将C#对象序列化为JSON以及在客户端应用程序的另一端反序列化它们时,我们一直大量使用TypeNameHandling.Arrays。但是,似乎Json.NET的XmlNodeConverter不适合此设置,在反序列化JSON时抛出错误,例如:{'people':{'$type':'System.Collections.Generic.List`1[[MyNamespace.Person,MyDll]],mscorlib','$values':[{'name':'Alan'},{'name':'Bob'}]}}原因抛出异常是因
我有一个具有接口(interface)类型属性的类,例如:publicclassFoo{publicIBarBar{get;set;}}我还有多个可以在运行时设置的IBar接口(interface)的具体实现。其中一些具体类需要自定义JsonConverter来进行序列化和反序列化。利用TypeNameHandling.Auto选项,需要IBar类的非转换器可以完美地序列化和反序列化。另一方面,自定义序列化类没有$type名称输出,虽然它们按预期序列化,但不能反序列化为具体类型。我试图在自定义JsonConverter中自己写出$type名称元数据;然而,在反序列化时,转换器将被完全绕
我正在尝试序列化和反序列化abstract类列表(mustinheritforvb),显然其中只有派生类的实例。我用JsonProperty(ItemTypeNameHandling=TypeNameHandling.Auto)修饰了列表参数,获得如下所示的输出:但是我反序列化的时候一直说他不能反序列化一个抽象类。http://james.newtonking.com/json/help/index.html?topic=html/SerializeTypeNameHandling.htmpublicclassConcreteClass{privateObservableCollect
我正在运营一个小型网站,用户可以在其中上传JSON中定义的自定义“对象”。最近我了解到使用JSON和自动类型反序列化可能存在的威胁:JSONproblem.我想我明白问题所在,但我必须问清楚。如果我只用给定的特定类型反序列化传入的JSON(这里是MyObject)JsonConvert.DeserializeObject(json,settings);并且里面没有类型MyObject并且没有MyObject的任何成员的子类型有类型System.Object或dynamic没有什么会变坏的,对吧?TypeNameHandling的settings设置为TypeNameHandling.A
我有一些内部属性的类,我也想将它们序列化为json。我怎样才能做到这一点?例如publicclassFoo{internalintnum1{get;set;}internaldoublenum2{get;set;}publicstringDescription{get;set;}publicoverridestringToString(){if(!string.IsNullOrEmpty(Description))returnDescription;returnbase.ToString();}}使用保存Foof=newFoo();f.Description="FooExample";
我想通过json.net序列化这段代码:publicinterfaceITestInterface{stringGuid{get;set;}}publicclassTestClassThatImplementsTestInterface1{publicstringGuid{get;set;}}publicclassTestClassThatImplementsTestInterface2{publicstringGuid{get;set;}}publicclassClassToSerializeViaJson{publicClassToSerializeViaJson(){this.C
我想通过json.net序列化这段代码:publicinterfaceITestInterface{stringGuid{get;set;}}publicclassTestClassThatImplementsTestInterface1{publicstringGuid{get;set;}}publicclassTestClassThatImplementsTestInterface2{publicstringGuid{get;set;}}publicclassClassToSerializeViaJson{publicClassToSerializeViaJson(){this.C
我正在尝试序列化/反序列化Dictionary如果对象是简单类型,这似乎可以正常工作,但当对象更复杂时,它就不起作用了。我有这门课:publicclassUrlStatus{publicintStatus{get;set;}publicstringUrl{get;set;}}在我的字典中,我添加了List带有“RedirectChain”键和一些带有“Status”、“Url”、“ParentUrl”键的简单字符串。我从JSON.Net返回的字符串如下所示:{"$type":"System.Collections.Generic.Dictionary`2[[System.String,
我正在尝试序列化/反序列化Dictionary如果对象是简单类型,这似乎可以正常工作,但当对象更复杂时,它就不起作用了。我有这门课:publicclassUrlStatus{publicintStatus{get;set;}publicstringUrl{get;set;}}在我的字典中,我添加了List带有“RedirectChain”键和一些带有“Status”、“Url”、“ParentUrl”键的简单字符串。我从JSON.Net返回的字符串如下所示:{"$type":"System.Collections.Generic.Dictionary`2[[System.String,