json.net

Why does Json.NET fail to serialize a X509Certificate2?

こ雲淡風輕ζ 提交于 2020-05-15 04:57:48
问题 Whenever I try to serialize an X509Certificate2 instance with Json.NET (without using its ISerializable implementation, but electing to ignore it), Json.NET throws an exception. The exception message is "A member with the name 'CertContext' already exists on 'System.Security.Cryptography.X509Certificates.X509Certificate2'. Use the JsonPropertyAttribute to specify another name." I wrote a program that reproduces it: using System.Reflection; using System.Security.Cryptography.X509Certificates;

JSON.NET Unable to deserialize ulong flag type enum

送分小仙女□ 提交于 2020-05-14 08:52:28
问题 I have a flag type of enum and I would like it to be serialized not as string but as number. There is no problem about serializing but json.net unable to deserialize it. public class ForceNumericFlagEnumConverter : JsonConverter { public override bool CanConvert(Type objectType) { if (!(Nullable.GetUnderlyingType(objectType) ?? objectType).IsEnum) return false; return HasFlagsAttribute(objectType); } public override bool CanRead { get { return false; } } public override bool CanWrite { get {

JSON.NET Unable to deserialize ulong flag type enum

感情迁移 提交于 2020-05-14 08:52:11
问题 I have a flag type of enum and I would like it to be serialized not as string but as number. There is no problem about serializing but json.net unable to deserialize it. public class ForceNumericFlagEnumConverter : JsonConverter { public override bool CanConvert(Type objectType) { if (!(Nullable.GetUnderlyingType(objectType) ?? objectType).IsEnum) return false; return HasFlagsAttribute(objectType); } public override bool CanRead { get { return false; } } public override bool CanWrite { get {

JSON.NET Unable to deserialize ulong flag type enum

£可爱£侵袭症+ 提交于 2020-05-14 08:51:33
问题 I have a flag type of enum and I would like it to be serialized not as string but as number. There is no problem about serializing but json.net unable to deserialize it. public class ForceNumericFlagEnumConverter : JsonConverter { public override bool CanConvert(Type objectType) { if (!(Nullable.GetUnderlyingType(objectType) ?? objectType).IsEnum) return false; return HasFlagsAttribute(objectType); } public override bool CanRead { get { return false; } } public override bool CanWrite { get {

Json.Net deserialize out of memory issue

好久不见. 提交于 2020-05-13 01:13:49
问题 I got a Json, which contains among others a data field which stores a base64 encoded string. This Json is serialized and send to a client. On client side, the newtonsoft json.net deserializer is used to get back the Json. However, if the data field becomes large (~ 400 MB), the deserializer will throw an out of memory exception: Array Dimensions exceeded supported Range . I also see in Task-Manager, that memory consumption really grows fast. Any ideas why this is? Is there a maximum size for

JObject how to read values in the array?

点点圈 提交于 2020-05-12 11:08:09
问题 This is the json string: {"d":[{"numberOfRowsAdded":"26723"}]} string json = DAO.getUploadDataSummary(); JObject uploadData = JObject.Parse(json); string array = (string)uploadData.SelectToken("d"); How do I change the code to reader the values in 'numberOfRowsAdded? 回答1: JObject uploadData = JObject.Parse(json); int rowsAdded = Convert.ToInt32((string)uploadData["d"][0]["numberOfRowsAdded"]) 回答2: You need to cast to JArray : string json = "{\"d\":[{\"numberOfRowsAdded\":\"26723\"}]}";

JObject how to read values in the array?

寵の児 提交于 2020-05-12 11:05:13
问题 This is the json string: {"d":[{"numberOfRowsAdded":"26723"}]} string json = DAO.getUploadDataSummary(); JObject uploadData = JObject.Parse(json); string array = (string)uploadData.SelectToken("d"); How do I change the code to reader the values in 'numberOfRowsAdded? 回答1: JObject uploadData = JObject.Parse(json); int rowsAdded = Convert.ToInt32((string)uploadData["d"][0]["numberOfRowsAdded"]) 回答2: You need to cast to JArray : string json = "{\"d\":[{\"numberOfRowsAdded\":\"26723\"}]}";

JObject how to read values in the array?

故事扮演 提交于 2020-05-12 11:05:08
问题 This is the json string: {"d":[{"numberOfRowsAdded":"26723"}]} string json = DAO.getUploadDataSummary(); JObject uploadData = JObject.Parse(json); string array = (string)uploadData.SelectToken("d"); How do I change the code to reader the values in 'numberOfRowsAdded? 回答1: JObject uploadData = JObject.Parse(json); int rowsAdded = Convert.ToInt32((string)uploadData["d"][0]["numberOfRowsAdded"]) 回答2: You need to cast to JArray : string json = "{\"d\":[{\"numberOfRowsAdded\":\"26723\"}]}";

json.net limit maxdepth when serializing

混江龙づ霸主 提交于 2020-05-09 02:09:07
问题 We're using Asp.Net WebAPI with Entity Framework (with lazy loading) and using Json.net for serializing the data to json before returning the data to the client. We are experiencing intermittent sudden spikes in memory usage which we suspect might originate with json.net not recognizing reference loops when serializing data (since Entity Framework might be doing some lazy loading voodoo with proxy classes which goes under the radar of json.net) I thought I'd limit how deep Json.net was

json.net limit maxdepth when serializing

China☆狼群 提交于 2020-05-09 02:08:10
问题 We're using Asp.Net WebAPI with Entity Framework (with lazy loading) and using Json.net for serializing the data to json before returning the data to the client. We are experiencing intermittent sudden spikes in memory usage which we suspect might originate with json.net not recognizing reference loops when serializing data (since Entity Framework might be doing some lazy loading voodoo with proxy classes which goes under the radar of json.net) I thought I'd limit how deep Json.net was