json.net

Why System.Version in JSON string does not deserialize correctly?

本小妞迷上赌 提交于 2019-12-04 22:41:48
Context: I need to pass an object containing a large number of properties/fields (to UI Layer from Middle Tier Layer). Among this list of properties, one is of type Version which is not getting deserialized correctly from JSON string format. I have a chosen JSON format over XML as JSON serialization to string will return short string result. Problem: System.Version does not get deserialized correctly. I have tried two different .NET Libraries. Following are the code snippets for each: Code Snippet 1 using ServiceStack .NET library : var version = new Version(1, 2, 3, 0); string reportJSON =

JSON.Net serializer ignoring JsonProperty?

旧街凉风 提交于 2019-12-04 22:30:00
I have the following entity class: public class FacebookComment : BaseEntity { [BsonId(IdGenerator = typeof(ObjectIdGenerator))] [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] [JsonProperty("_id")] public ObjectId Id { get; set; } public int? OriginalId { get; set; } public DateTime Date { get; set; } public string Message { get; set; } public string Sentiment { get; set; } public string Author { get; set; } } When this object is serialized to JSON, I want the Id field to be written as "_id":{...}. AFAIK, I should just have to pass the desired propertyname to the JsonProperty attribute;

What is the existingValue parameter used for in the ReadJson method of a JsonConverter?

牧云@^-^@ 提交于 2019-12-04 22:18:55
When creating a custom Json Converter one of the methods which needs to be overridden is: public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) What is "existingValue" parameter used for? What does the variable name "existingValue" mean in this context? Simply put, the existingValue parameter gives you the existing or default value of the object that will ultimately be replaced with the value returned from the ReadJson method. This gives the ReadJson method the chance to evaluate the existing value when determining what to return.

Is the Json.NET JsonSerializer threadsafe?

≯℡__Kan透↙ 提交于 2019-12-04 22:14:44
I'm trying to reduce the amount of garbage my web service generates, and I noticed that we're creating a new Json.NET JsonSerializer instance for each request. It is not the most lightweight object ever, so I'm wondering if I can just create a single instance and reuse it for all requests. Primarily this requires that it be threadsafe during serialization and deserialization. The documentation doesn't say whether it's threadsafe or not. Inspecting the code it appears that the serialization and deserialization methods are threadsafe, as long as you don't change any settings on the object at the

Serialize NaN values into JSON as nulls in JSON.NET

浪子不回头ぞ 提交于 2019-12-04 20:33:02
问题 Most Json parsers don't serialize NaN, because in Javascript, NaN is not a constant. Json.Net, however, does serialize NaN values into NaN, which means it outputs invalid Json; attempting to deserialize this Json will fail with most parsers. (We're deserializing in WebKit.) We have hacked the Json.Net code to output null values when passed NaN, but this seems like a poor solution. Douglas Crockford (once) recommended using nulls in place of NaNs: http://www.json.org/json.ppt (Look at slide 16

VB.NET Deserialize JSON to anonymous object using newtonsoft returned error

喜欢而已 提交于 2019-12-04 19:41:53
I would like to deserialize the returned JSON from a service call in VB.NET to an anonymous type but I was having error. It works in C# using dynamic type but i dont know how to do it in VB. Here is my JSON returned from a web service call: {"format":"png","height":564,"width":864} Here is my VB code json above assigned to param text: Dim testObj = Newtonsoft.Json.JsonConvert.DeserializeObject(text) But when i tried to access testObj.format, an exception was thrown with message {"Public member 'format' on type 'JObject' not found."} I already have added Option Strict Off . I dont want to use

VB.net deserialize JSON with JSON.net

落爺英雄遲暮 提交于 2019-12-04 19:38:49
I look for a solution to my problem since 2 weeks without solution. I would like to deserialize JSON with JSON.NET, but noway ... I create class but when i deserialize the object stay empty (Nothing). Here the JSON : {"plannifReponse": {"@competence":"Abonnement","plannifDonnees": {"entry": [ {"key":"2013-8-11T00:00","value": {"creneaux": [ {"@jour":"2013-8-11T00:00","@heure":"09","@minute":"30","nombreRessources":10}, {"@jour":"2013-8-11T00:00","@heure":"10","@minute":"30","nombreRessources":2}, {"@jour":"2013-8-11T00:00","@heure":"17","@minute":"30","nombreRessources":5}, {"@jour":"2013-8

Efficient way of storing and retrieving Large Json ( 100 mb +) from a file using this article and Json.Net

爱⌒轻易说出口 提交于 2019-12-04 19:29:00
I have been trying to figure out the best way to store and retrieve data from a file containing Json using JSon.net. During my research i found couple of ways. http://www.drdobbs.com/windows/parsing-big-records-with-jsonnet/240165316 http://www.ngdata.com/parsing-a-large-json-file-efficiently-and-easily/ Jackson Api ( only available for Java ) Can any of this method be used with Json.Net? Is there an actual implementation available for the article at DrDoobs? I could not figure out the HandleToken(reader.TokenType, reader.Value) method. Current Stats: Around 5 min to write the Json of size ~

Formatting output of Newtonsoft.Json.JsonConvert.SerializeObject(dataSet) [duplicate]

放肆的年华 提交于 2019-12-04 19:28:41
This question already has an answer here: How do I make my JSON less verbose? 5 answers I have a DataTable. When it's serialized into JSON with Newtonsoft.Json.JsonConvert.SerializeObject(dataTable) I get results in the following format: [ { "CLICK_KEY": 6254523744, "WEB_SERVER_KEY": 291, "PREV_CLICK_KEY": 0, "NEXT_CLICK_KEY": 0, "SESSION_KEY": 214981151, *more key value pairs* }, { "CLICK_KEY": 6254523745, "WEB_SERVER_KEY": 291, "PREV_CLICK_KEY": 0, "NEXT_CLICK_KEY": 0, "SESSION_KEY": 214746780 *more key value pairs* }, *many more objects (for each row)* ] Since I have many columns and many

Newtonsoft JsonConvert.SerializeObject ignoring JsonProperty if name is uppercase

南笙酒味 提交于 2019-12-04 19:22:58
I want to be able to use the CamelCasePropertyNameContractResolver but override it for specific property names. For this, I use the JsonProperty attribute. This works fine except when the name that I choose is fully uppercase. Any ideas what's wrong or how to get around it? In the example below, Bar is serialized to "BAR" when I don't use the CamelCasePropertyNameContractResolver, but is serialized to "bar" when I do use the resolver. Foo and CamelCaseProperty are serialized correctly in both scenarios. using Newtonsoft.Json; using Newtonsoft.Json.Serialization; namespace ConsoleTester { class