json.net

Usage of non-default constructor breaks order of deserialization in Json.net

会有一股神秘感。 提交于 2019-12-17 22:28:14
问题 When deserializing an object graph with parent child relationships using Json.net, the use of non-default constructors breaks the order of deserialization such that child objects are deserialized (constructed and properties assigned) before their parents, leading to null references. From experimentation it appears that all non-default-constructor objects are instantiated only after all default-constructor objects, and oddly it seems in the reverse order to the serialization (children before

Polymorphic JSON Deserialization failing using Json.Net

≯℡__Kan透↙ 提交于 2019-12-17 22:24:24
问题 I'm trying to deserialize some JSON to various sub-classes using a custom JsonConverter I followed this almost to the point. My abstract base-class: abstract class MenuItem { public String Title { get; set; } public String Contents { get; set; } public List<MenuItem> Submenus { get; set; } public String Source { get; set; } public String SourceType { get; set; } public abstract void DisplayContents(); } And my derived JsonConverter : class MenuItemConverter : JsonConverter { public override

How to improve JSON deserialization speed in .Net? (JSON.net or other?)

不羁的心 提交于 2019-12-17 21:49:16
问题 We're considering replacing (some or many) 'classic' SOAP XML WCF calls by JSON (WCF or other) calls, because of the lower overhead and ease of use directly in Javascript. For now, we've just added an additional Json endpoint to our web service and added WebInvoke attributes to some operations and tested them. Everything works fine, using C# .Net clients or Javascript clients. So far so good. However, it seems like deserializing big JSON strings to objects in C# .Net is much slower than

JSON.NET: Get Specific JSON Date Value

自闭症网瘾萝莉.ら 提交于 2019-12-17 21:34:06
问题 In my VB.NET project, using JSON.NET, I've got a JSON from a Web API that has a value representing a date in the yyyy-MM-ddTHH:mm:ss format, and I'd like to simply get that value. Here's more or less what the JSON looks like: { "REQ_DATE": "2016-01-17T12:27:57", "REQ_TYPE": "Vacation", "HOURS": 500.0, "LEAVE_TIME": "8:00 AM", "LEAVE_DATE": "2016-01-23T00:00:00", "DUE_TIME": "8:00 AM", "DUE_DATE": "2016-01-24T00:00:00", } So I should just serialize it and do what I will with the value, right?

How can I deserialize this JSON with JsonConvert?

核能气质少年 提交于 2019-12-17 21:32:13
问题 I have this JSON and I cannot figure out how to convert it to a List of objects in C#. Here is the JSON: { "2": { "sell_average": 239, "buy_average": 238, "overall_average": 240, "id": 2 }, "6": { "sell_average": 184434, "buy_average": 182151, "overall_average": 189000, "id": 6 }, "8": { "sell_average": 11201, "buy_average": 1723, "overall_average": 180, "id": 8 } } And the code I've tried using: public class ItemSummaryModel { public string Id { get; set; } public ItemSummary ItemSummary {

Deserializing JSON in Visual Basic .NET

余生长醉 提交于 2019-12-17 21:17:29
问题 Wondering if you could help me create a VB.Net class into which I can deserialize the following JSON response: { "id":86, "name":"Tom", "likes": { "actors":[ ["Clooney",2,30,4], ["Hanks",104,15,1] ] }, "code":8 } I have the following: Class mLikes Public actors As IList(Of IList(Of String)) end Class and Class Player <JsonProperty(PropertyName:="id")> Public Id As Integer <JsonProperty(PropertyName:="name")> Public Name As String <JsonProperty(PropertyName:="likes")> Public Likes As mLikes

Json.net Add property to every class containing of a certain type

纵饮孤独 提交于 2019-12-17 21:11:15
问题 I want to add a property to my json for every property of type DateTime. I have a custom converter and have an override on CreateProperties (see below). When debugging the returned list of properties holds the new values but by the time the json reaches the browser it does not contain the new properties protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var properties = base.CreateProperties(type, memberSerialization); foreach(var

Generate schema using StringEnumConverter

旧城冷巷雨未停 提交于 2019-12-17 21:05:53
问题 Is it possible to generate a schema with Json.NET that outputs enum values as strings rather than integers? I noticed someone had forked the code to do this, but was wondering if there's any other way to do this, or if there are any plans to do it. EDIT To be clear, I'm trying to use this to generate a schema: var schemaGenerator = new JsonSchemaGenerator(); var schema = schemaGenerator.Generate(typeof(Class1)); return schema.ToString(); 回答1: Install Newtonsoft.Json.Schema package via NuGet

Getting an OutOfMemoryException while serialising to JSON?

北慕城南 提交于 2019-12-17 21:01:01
问题 I am serializing , a MultiDictionary<String,Object> http://powercollections.codeplex.com/ to json . It has 618 elements with elements being deeply nested ,i.e. a single Object may have several dictionary like objects in it . I am using JSON.Net String json = JsonConvert.SerializeObject(json, Newtonsoft.Json.Formatting.Indented); what am i missing ? MORE INFO: - This was working fine till i was using dynamic , i had to switch to MultiDictionary to allow multiple properties of the same name .

How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?

拜拜、爱过 提交于 2019-12-17 20:42:54
问题 I am trying to consume a web service that claims to return JSON, but actually always returns JSONP. I don't see a way to change that service's behavior. I would like to use NewtonSoft Json.Net to parse the result. I have declared a class, let's call it MyType that I want to deserialize the inner JSON result into. JSONP: parseResponse({ "total" : "13,769", "lower" : "1", "upper" : "20"}) As you can see this is not correct JSON as it has parseResponse( prefix and ) suffix. While this example is