datacontractjsonserializer

DataContractJsonSerializer and maxItemsInObjectGraph

天大地大妈咪最大 提交于 2019-12-11 11:34:43
问题 How can I set the maxItemsInObjectGraph for the DataContractJsonSerializer? I get an error saying "Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota." Where does the number 65536 come from. The documentation for DataContractJsonSerializer says the default is Int32.MaxValue. I tried to set it in the behavior configuration: <endpointBehaviors> <behavior name="WebBehavior"> <webHttp />

Using DataContractJsonSerializer to create a Non XML Json file

余生长醉 提交于 2019-12-11 08:27:27
问题 I want to use the DataContractJsonSerializer to serialize to file in JsonFormat. The problem is that the WriteObject method only has 3 options XmlWriter, XmlDictionaryWriter and Stream. To get what I want I used the following code: var js = new DataContractJsonSerializer(typeof(T), _knownTypes); using (var ms = new MemoryStream()) { js.WriteObject(ms, item); ms.Position = 0; using (var sr = new StreamReader(ms)) { using (var writer = new StreamWriter(path, false)) { string jsonData = sr

How do I get DataContractJsonSerializer to use concrete type in type hint when serializing generic class from interface

青春壹個敷衍的年華 提交于 2019-12-11 06:14:51
问题 I have a set of classes as follows: a Command, which Executes and stores a Result; a Response, which is created as in order to return the Result in a serialized form (plus extra metadata which I've left out). The Response.Result must be of type object, as it is used for a bunch of different commands, each of which can have a Result of any type at all. The Command is generic, and I'd like it to accept an interface rather than concrete type, but when I do, the serialized response contains the

There was an error deserializing the object of type RD.Details. '�19.95 Per Person' contains invalid UTF8 bytes

半腔热情 提交于 2019-12-11 05:28:07
问题 When I try and deserialize a JSON string which contains a £ symbol I get the exception. There was an error deserializing the object of type RD.Details. '�19.95 Per Person' contains invalid UTF8 bytes. The string which I log is as below: { "Promotions":[ { "Name":"Traditional Afternoon Tea £19.95 Per Person", "PromotionId":20175, "Quantity":2 } ] } This is how I am deserializing: var responseJsonSerializer = new DataContractJsonSerializer(typeof(TR)); Stream serializedStream; string

Deserialization of JSON object by using DataContractJsonSerializer in C#

旧巷老猫 提交于 2019-12-10 23:43:33
问题 I'm sure this question has been asked over and over again, but for some reason, I still can't manage to get this to work. I want to deserialize a JSON object that contains a single member; a string array: [{"idTercero":"cod_Tercero"}] This is the class that I'm trying to deserialize into: [DataContract] public class rptaOk { [DataMember] public string idTercero { get; set; } public rptaOk() { } public rptaOk(string idTercero) { this.idTercero = idTercero; } } This is the method that I try to

Can DataContractJsonSerializer handle cyclic references?

夙愿已清 提交于 2019-12-10 10:47:59
问题 Are there any serialization/deserialization scenarios that DataContractSerializer can handle, while DataContractJsonSerializer can't ? In particular, I am thinking of circular references: this MSDN page explains how circular references can be managed by DataContractSerializer via the use of IsReference = true in the DataContractAttribute constructor. On the other hand, the DataContractAttribute.IsReference documentation does not explicitly state that its applicability is limited to

De-serialize JSON return empty data

旧城冷巷雨未停 提交于 2019-12-08 12:15:51
问题 I use api url to get json response http://localhost/WaWebService/Json/NodeDetail/Demo/SCADA_NODE_DEMO Using Postman software I verify there is response { "Result": { "Ret": 0 }, "Node": { "ProjectId": 1, "NodeId": 1, "NodeName": "SCADA_NODE_DEMO", "Description": "", "Address": "SALMAN-MUSHTAQ", "Port1": 0, "Port2": 0, "Timeout": 0 } } After it I make class class Result { public int Ret { get; set; } } public class Node { public int ProjectId { get; set; } public int NodeId { get; set; }

Using DataContractJsonSerializer, deserialization of JSON string into C# object which has list & interface as properties

时光总嘲笑我的痴心妄想 提交于 2019-12-07 20:40:29
问题 I am working on a c#.dotNet project which invokes a 3rd party REST service. Sample Class Structure : [Serializable] [DataContract(Name = "MainClass")] [KnownType(typeof(Class1))] [KnownType(typeof(Class2))] public class MainClass : IMainInterface { public MainClass() { Value2 = new List<IClass2>(); } [DataMember(Name = "class")] public IClass1 Value1 { get; set; } [DataMember(Name = "classes")] public List<IClass2> Value2 { get; set; } } [Serializable] [Export(typeof(IClass1))]

Can DataContractJsonSerializer handle cyclic references?

大憨熊 提交于 2019-12-06 16:01:19
Are there any serialization/deserialization scenarios that DataContractSerializer can handle, while DataContractJsonSerializer can't ? In particular, I am thinking of circular references: this MSDN page explains how circular references can be managed by DataContractSerializer via the use of IsReference = true in the DataContractAttribute constructor. On the other hand, the DataContractAttribute.IsReference documentation does not explicitly state that its applicability is limited to DataContractSerializer . Will DataContractJsonSerializer also honor the IsReference property? There's nothing

Using DataContractJsonSerializer, deserialization of JSON string into C# object which has list & interface as properties

 ̄綄美尐妖づ 提交于 2019-12-06 05:57:24
I am working on a c#.dotNet project which invokes a 3rd party REST service. Sample Class Structure : [Serializable] [DataContract(Name = "MainClass")] [KnownType(typeof(Class1))] [KnownType(typeof(Class2))] public class MainClass : IMainInterface { public MainClass() { Value2 = new List<IClass2>(); } [DataMember(Name = "class")] public IClass1 Value1 { get; set; } [DataMember(Name = "classes")] public List<IClass2> Value2 { get; set; } } [Serializable] [Export(typeof(IClass1))] [ExportMetadata("IClass1", "Class1")] [DataContract(Name = "class1")] public class Class1 : IClass1 {