json.net

Adding Iso8601TimeSpanConverter to JsonConverter list throws ArrayTypeMismatch exception

本小妞迷上赌 提交于 2020-01-02 08:38:09
问题 I'm using AutoRest to auto generate a c# class for a REST API from a Swagger definition file. The problem is that when the client class initialize methos is executed, it throws an ArrayTypeMismatch exception in the following code: SerializationSettings = new JsonSerializerSettings { Formatting = Formatting.Indented, DateFormatHandling = DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = DateTimeZoneHandling.Utc, NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling =

Self Hosted WCF Rest service ERROR : Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported

被刻印的时光 ゝ 提交于 2020-01-02 08:24:11
问题 I have a WCF Rest service that's self hosted. It works fine until I decided I have to use JToken (Newtonsoft.Json.Linq.JToken). I then got the error : Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself. I've seen all the answers from this post, this one and others. The fact is, I'm hosting my services within an internal program (in the

Build JSON Hierarchy from Structured Data

梦想的初衷 提交于 2020-01-02 07:10:13
问题 C# | .NET 4.5 | Entity Framework 5 I have data coming back from a SQL Query in the form of ID,ParentID,Name. I'd like to take that data and parse it into a Hierarchical JSON string. So far it seems to be much more of a daunting task than it should be. Since I'm using Entity the data comes back nicely to me as an IEnumerable. Now I believe I just need some form of recursion, but I'm not quite sure where to start. Any help is appreciated. Data Returns as id parentId name 1 1 TopLoc 2 1 Loc1 3 1

Is it possible to return a pre-encoded JSON string in a SignalR hub method?

两盒软妹~` 提交于 2020-01-02 07:05:21
问题 In an MVC project, I have a method on a hub similar to this: public string Foo() { return DoCrazyThingThatReturnsJson(); } Unfortunately SignalR (or something) takes the encoded JSON string and happily encodes it, then returns it, so browser be like LOLWTF. Is there a way to skip this second encoding? 回答1: Looking at this here: We assume that any ArraySegment is already JSON serialized it seems like something like this may work (note that I haven't tried it, so no promises): string jsonString

Is it possible to return a pre-encoded JSON string in a SignalR hub method?

五迷三道 提交于 2020-01-02 07:05:13
问题 In an MVC project, I have a method on a hub similar to this: public string Foo() { return DoCrazyThingThatReturnsJson(); } Unfortunately SignalR (or something) takes the encoded JSON string and happily encodes it, then returns it, so browser be like LOLWTF. Is there a way to skip this second encoding? 回答1: Looking at this here: We assume that any ArraySegment is already JSON serialized it seems like something like this may work (note that I haven't tried it, so no promises): string jsonString

How to serialize a large JSON object directly to HttpResponseMessage stream?

半城伤御伤魂 提交于 2020-01-02 05:48:09
问题 Is there any way to stream a large JSON object directly to the HttpResponseMessage stream? Here is my existing code: Dictionary<string,string> hugeObject = new Dictionary<string,string>(); // fill with 100,000 key/values. Each string is 32 chars. HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent( content: JsonConvert.SerializeObject(hugeObject), encoding: Encoding.UTF8, mediaType: "application/json"); Which works fine for smaller

JSON.NET: How to Serialize Nested Collections

孤人 提交于 2020-01-02 05:13:41
问题 This is driving me nuts... I am serializing a List to JSON using Json.net. I expect this JSON: { "fieldsets": [ { "properties": [ { "alias": "date", "value": "2014-02-12T00:00:00" }, { "alias": "time", "value": null } ], "alias": "eventDates", "disabled": false } ] } But instead I get this: { "fieldsets": [ { "properties": [ { "values": [ { "alias": "date", "value": "2014-07-13T00:00:00" }, { "alias": "time", "value": "Registration begins at 8:00 AM; walk begins at 9:00 AM" } ] } ], "alias":

JSON.NET: How to Serialize Nested Collections

爱⌒轻易说出口 提交于 2020-01-02 05:13:06
问题 This is driving me nuts... I am serializing a List to JSON using Json.net. I expect this JSON: { "fieldsets": [ { "properties": [ { "alias": "date", "value": "2014-02-12T00:00:00" }, { "alias": "time", "value": null } ], "alias": "eventDates", "disabled": false } ] } But instead I get this: { "fieldsets": [ { "properties": [ { "values": [ { "alias": "date", "value": "2014-07-13T00:00:00" }, { "alias": "time", "value": "Registration begins at 8:00 AM; walk begins at 9:00 AM" } ] } ], "alias":

Json.NET: deserialize nested arrays into strongly typed object

ぐ巨炮叔叔 提交于 2020-01-02 04:31:09
问题 I'm writing client application, which should process server responses. Responses are in JSON. I decided to use Json.NET to deserialize them. And I couldn't simplify or modify those responses (on server side). Particular difficulties of this specific JSON response is that different object types is in same array: hash and array of files. So, I would like to deserialize this array straight ahead into strongly typed object, rather than array of objects. I think that it should be possible to

Why is Newtonsoft.Json so prone to assembly version conflicts?

元气小坏坏 提交于 2020-01-02 04:05:14
问题 I have noticed that we often get assembly version conflicts in our project, and 90% of the time it's Newtonsoft.Json at the bottom. There are many questions on SO specifically for Newtonsoft.Json conflicts - the infamous "Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0" for example. Searching for "assembly 'Newtonsoft.Json, Version=6.0.0.0" gives 37 questions - a lot of them highly upvoted. Or this one about 4.5.0.0. Is there any explanation why this happen so often with