json.net

Specifying default value for a property in relation to other property in Json.NET

非 Y 不嫁゛ 提交于 2020-01-03 03:39:04
问题 I am wondering if there is a way to set default value for a property in relation to other property of the same class in Json.NET e.g like this: public class JsonsoftExample { [JsonProperty(Required = Required.Always)] public DateTime Start { get; set; } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] [DefaultValue(Start.AddHours(1))] public DateTime End { get; set; } } What I am trying to accomplish here is to populate End with DateTime value that is one hour later than

How do I convert a complex json object to CLR object with json.net?

淺唱寂寞╮ 提交于 2020-01-03 03:33:05
问题 sorry for a dumb question but I haven't found any solution for this. Here is my JSON: { "Id": "1", "Parent.Id": "1", "Agent.Id": "1", "Agent.Profile.FullName": "gena", "Fee": "10.1200", "FeeManagementDate": "29/11/2013", "Contact.Name": "Genady", "Contact.Telephone": "000000000", "Contact.Email": "gena@email.com", "AgreementUrl": "http://www.test.com/agreement" } Here is my object public class ManagementDetailsViewModel : ViewModel<int> { public ManagementDetailsViewModel() { } public string

How do I convert a complex json object to CLR object with json.net?

那年仲夏 提交于 2020-01-03 03:33:05
问题 sorry for a dumb question but I haven't found any solution for this. Here is my JSON: { "Id": "1", "Parent.Id": "1", "Agent.Id": "1", "Agent.Profile.FullName": "gena", "Fee": "10.1200", "FeeManagementDate": "29/11/2013", "Contact.Name": "Genady", "Contact.Telephone": "000000000", "Contact.Email": "gena@email.com", "AgreementUrl": "http://www.test.com/agreement" } Here is my object public class ManagementDetailsViewModel : ViewModel<int> { public ManagementDetailsViewModel() { } public string

Pass Base64 encoded string using JsonTextReader value as new stream

风格不统一 提交于 2020-01-03 02:59:25
问题 We are consuming large JSON streams from an HTTP Post request. The goal is to stream the incoming body as JSON using JsonTextReader and extract the embedded base64 encoded binary files to disk. In XML, an equivalent method might be XMLReader.ReadElementContentAsBase64Async. Using JSON.NET, as we iterative how do we send the each item of the encodedImages array into a FileStream without holding the whole string in memory. Example JSON Object: { "company":"{clientCompany}", "batchName":"

JSON.NET Parses +00:00 timezone as local times, but Z as UTC

陌路散爱 提交于 2020-01-03 02:28:23
问题 I've been having an issue with Web API parsing datetimes incorrectly which I have tracked down to JSON.NET. The issue is that if I send this datetime: 2015-07-28T19:06:01.000+00:00 in a JSON PUT request, the DateTime parsed in my model will be converted to a time in the local server timezone, with the C# datetime kind of local, not UTC. If I send this datetime: 2015-07-28T19:06:01.000Z It will correctly keep it as UTC, with the C# datetime kind of UTC which is what I want. I can fix this, by

problem of performance : optimize JSON deserialization speed in c#

可紊 提交于 2020-01-03 02:24:07
问题 I have a problem concerning a complex JSON deserialization in c# using newtonsoft.json 1- my feed provider send me a gz file push through POST request each 3 seconds (size between 200ko and 3000 ko) 2- I get it back, unzip it and download the JSON file inside on my server 3- I need to treat this JSON file directly after receiving it (so in realtime). What I do is using a "File System watcher" class included into a timed background task (using "TimedHostedService" class) When a json file is

JSON deserialization of derived types

空扰寡人 提交于 2020-01-03 01:58:20
问题 class Attribute1 { } class Attribute2 : Attribute1 { } class class1 { Attribute1 attr1; } class class2 : class1 { Attribute2 attr2; } var serializerSettings = new JsonSerializerSettings(){TypeNameHandling = TypeNameHandling.Objects}; class2 a = SomeValidObjectoftype Class2; string serializedClass2 = JsonConvert.SerializeObject(a, serializerSettings); var am = JsonConvert.DeserializeObject<Class2>(serializedClass1); All the above are JSON properties and objects. What I am trying to do is

Deserializing json into a list of objects - Cannot create and populate list type [duplicate]

假装没事ソ 提交于 2020-01-02 12:26:50
问题 This question already has answers here : Json.net serialization of custom collection implementing IEnumerable<T> (2 answers) Closed 3 years ago . I'm trying to deserialize json (here is link to it http://antica.e-sim.org/apiFights.html?battleId=3139&roundId=1 ) into a list of objects. This is my class: public class RootObject { public int Damage { get; set; } public int Weapon { get; set; } public bool Berserk { get; set; } public bool DefenderSide { get; set; } public double

JSON.NET cannot deserialize a wrapped collection

↘锁芯ラ 提交于 2020-01-02 10:29:11
问题 I have a wrapped list that looks like this: [Serializable] public class OrderManager : IEnumerable<Order> { public OrderManager() { } private List<Order> orders = new List<Order>(); public void AddOrder(Order order) { orders.Add(order); } public IEnumerator<Order> GetEnumerator() { return orders.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return orders.GetEnumerator(); } } I include a field instance in a customer class like this:

How to disable TypeNameHandling when specified in attributes by using JsonSerializerSettings in Json.NET?

余生颓废 提交于 2020-01-02 09:42:07
问题 Sometimes I need to suppress output of "$type" properties by Json.NET even when specified by JsonPropertyAttribute.ItemTypeNameHandling. How can this be done? My root class looks like below: public class DomainResource { [JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)] public List<Extension> Extensions { get; set; } } And in addition I have a class hierarchy for Extension such as the following: public class Extension { readonly string url; public string Url { get { return url; } }