serialization

DataContractJsonSerializer generating Ghost string to JSON keys?

核能气质少年 提交于 2020-01-13 11:37:08
问题 DataContractJsonSerializer this is nice class added in the .net framework which can be used to serialize/desirealize object into JSON. Now following is the example i am trying [Serializable] class User { public string name; public string userId; } Now following is the output generated Output : Notice structure where only "name" is expected instead of k__BackingField Now this is the problem after digging so much i am not sure from where <> and _BackingField is coming ? { "<name>k__BackingField

DataContractJsonSerializer generating Ghost string to JSON keys?

白昼怎懂夜的黑 提交于 2020-01-13 11:37:08
问题 DataContractJsonSerializer this is nice class added in the .net framework which can be used to serialize/desirealize object into JSON. Now following is the example i am trying [Serializable] class User { public string name; public string userId; } Now following is the output generated Output : Notice structure where only "name" is expected instead of k__BackingField Now this is the problem after digging so much i am not sure from where <> and _BackingField is coming ? { "<name>k__BackingField

Why am I using the KnownType attribute wrong?

筅森魡賤 提交于 2020-01-13 11:23:22
问题 I am trying to deserialize a json response from a google api, so i thought i would define a couple classes to help with it: [DataContract] public class DetectionResult:ResponseData { [DataMember(Name="language")] public string Language { get; set; } [DataMember(Name="isReliable")] public bool IsReliable { get; set; } [DataMember(Name="confidence")] public double Confidence {get;set;} } [DataContract] public abstract class ResponseData { [DataMember(Name = "error")] public TranslationError

Why am I using the KnownType attribute wrong?

浪子不回头ぞ 提交于 2020-01-13 11:23:08
问题 I am trying to deserialize a json response from a google api, so i thought i would define a couple classes to help with it: [DataContract] public class DetectionResult:ResponseData { [DataMember(Name="language")] public string Language { get; set; } [DataMember(Name="isReliable")] public bool IsReliable { get; set; } [DataMember(Name="confidence")] public double Confidence {get;set;} } [DataContract] public abstract class ResponseData { [DataMember(Name = "error")] public TranslationError

Getting “because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly” error when deserializing a Json object

与世无争的帅哥 提交于 2020-01-13 11:13:10
问题 Please help me. Where I am missing info? I need to deserialize the following JSON string. {"results":[{"series":[{"name":"PWR_00000555","columns":["time","last"],"values":[["1970-01-01T00:00:00Z",72]]}]}]} For this, I have defined my class: public class Serie { public Serie() { this.Points = new List<object[]>(); } [JsonProperty(PropertyName = "results")] public string results { get; set; } [JsonProperty(PropertyName = "series")] public string sries { get; set; } [JsonProperty(PropertyName =

Getting “because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly” error when deserializing a Json object

[亡魂溺海] 提交于 2020-01-13 11:11:14
问题 Please help me. Where I am missing info? I need to deserialize the following JSON string. {"results":[{"series":[{"name":"PWR_00000555","columns":["time","last"],"values":[["1970-01-01T00:00:00Z",72]]}]}]} For this, I have defined my class: public class Serie { public Serie() { this.Points = new List<object[]>(); } [JsonProperty(PropertyName = "results")] public string results { get; set; } [JsonProperty(PropertyName = "series")] public string sries { get; set; } [JsonProperty(PropertyName =

HashMap De-Serialization

时间秒杀一切 提交于 2020-01-13 10:55:08
问题 I have a server/client app where I retrieve data from the server via Hessian/hessdroid. The data is very complex with HashMaps containing other HashMaps and images stored in byte arrays. I can display the data perfectly. To not always query the server, I´m using a data structure as a cache. This data object I save to SD card using ObjectOutputStream when closing the app. When I restart it, I read it back to memory with an ObjectInputStream. I´m having problems with the app only after reading

Serializing a System.Array to a XML String

自古美人都是妖i 提交于 2020-01-13 10:22:37
问题 I need to pass an array of strings to SQL Server 2005, and so I wrote a stored procedure which accpets a XML parameter and deals with it properly. My question is if there is any easy way to serialize a string[] to a XML string (not a file in the disk) directly in C# without having to code my own method using XDocument, XAttribute and the like. Example : I want to be able to transform something like new string[] { "a", "b", "c" } into something like <StringList><String>a</String><String>b<

Serializing a System.Array to a XML String

廉价感情. 提交于 2020-01-13 10:21:15
问题 I need to pass an array of strings to SQL Server 2005, and so I wrote a stored procedure which accpets a XML parameter and deals with it properly. My question is if there is any easy way to serialize a string[] to a XML string (not a file in the disk) directly in C# without having to code my own method using XDocument, XAttribute and the like. Example : I want to be able to transform something like new string[] { "a", "b", "c" } into something like <StringList><String>a</String><String>b<

Does BinaryFormatter apply any compression?

笑着哭i 提交于 2020-01-13 09:04:53
问题 When .NET's BinaryFormatter is used to serialize an object graph, is any type of compression applied? I ask in the context of whether I should worry about the object graph having many repeated strings and integers. Edit - Hold on, if strings are interned in .NET, there's no need to worry about repeated strings, right? 回答1: No, it doesn't provide any compression but you can compress the output yourself using the GZipStream type. Edit: Mehrdad has a wonderful example of this technique in his