json.net

How to change the Assemby and the Object type on the Newtonsoft.Json serialization/deserialization? Am using .NET MVC 3 and WPF

喜你入骨 提交于 2019-12-11 04:39:55
问题 I've looked and tried every single solution posted here, with no avail. My problem is: On a web solution (ASP.NET MVC 3 C# / Razor), I'm using Json.Net to serialize the data displayed on some reports, to be able to send it over to a WPF application. These reports results are a collection of Model objects. I have the same Model objects on the WPF application, so when I deserialize the Json string, I would like to bind the results accordingly (keeping the original Model object). The Assembly

Is there a way to deserialize my JSON without using a wrapper class for each item?

半城伤御伤魂 提交于 2019-12-11 04:28:47
问题 I am developing an ASP.NET application using JSON.NET that interfaces with a third-party REST API. The API returns JSON in the following format: [ { user: { id: 12345, first_name: "John", last_name: "Smith", created_at: "11/12/13Z00:00:00" } }, { user: { id: 12346, first_name: "Bob", last_name: "Adams", created_at: "12/12/13Z00:00:00" } } ] The user field is redundant, but I do not have control over the API so I have to live with it. I am currently using the following code to deserialize the

Can't deserialize Dictionary from JSON

笑着哭i 提交于 2019-12-11 04:18:02
问题 I have this class: class SoporteFile { public Evento[] eventos { get; set; } public Programacion[] programaciones { get; set; } public static Dictionary<int, object[]> soportes { get; set; } } Then I have the Soporte class Soporte { public Aviso[] avisos { get; set; } public Placa[] placas { get; set; } public Portada[] portadas { get; set; } public Efemeride[] efemerides { get; set; } public Comunicado[] comunicados { get; set; } } The class Dictionary from SoporteFile, should match the

Pass additional data to JsonConverter

耗尽温柔 提交于 2019-12-11 04:13:39
问题 I deserialize object where one of the properties is a foreign key (eg an identity value from a database table). During deserialization I would like to use a JsonConverter to retrieve the corresponding object from a collection. I know how to write a use custom JsonConverters. I don't know how to pass the collection to the JsonConverter, because the converter is specified at design time (like below), but the collection obviously only exists at runtime: <JsonConverter(GetType(JSonCustomConverter

How to parse only specific objects without deserializing the whole JSON file?

血红的双手。 提交于 2019-12-11 04:12:47
问题 I have a huge JSON file (tens of thousand of objects, >100 MB file) I'm trying to parse in order to extract specific objects. Since the file is this big I'm trying to deserialize only the specific part I need (if it's possible, that is) without having to deserialize the whole file. Said object should be found based on the the value of a specific property "arena_id":xxxxx contained in every object, objects that are formatted like this (stripped down version): {"object":"card","id":"61a908e8

Json.Net TypeNameHandling.Auto and Asp Web Api Controller gives unexpected behaviour

拜拜、爱过 提交于 2019-12-11 04:09:21
问题 Assume TypeNameHandling.Auto is used for Json.net in the following Web Api Controllers: class A {} class B : A {} class FooController : ApiController { public A Get() { return new A(); } } class BarController : ApiController { public A Get() { return new B(); } } Then I would expect the resulting Json to be: Foo {} Bar {'$type':...} However, the output of Bar is also {} . On the other hand, if the API controller returned IEnumerable<A> and we returned a lot of B 's then the type property is

Is it possible to serialize an object differently to deserializing it using Json.Net?

喜欢而已 提交于 2019-12-11 03:58:34
问题 Here is my example: JSON request string: { entity: '09f7cb28-0464-41c8-a20d-1b05eb1cda0a' } My request object: public class Request { public Request() { } [JsonProperty("entity")] private string EntityIdentifier { get; set; } public EntityObject Entity { get; set; } } I've got this to work so that the string is passed to the EntityIdentifier, which is fine, then in my code I find the actual entity using the entity identifier property, populate the Entity property with the found entity but

Json.Net Class hierarchy with ObservableCollection and INotifyPropertyChange gets serialized but not deserialized

99封情书 提交于 2019-12-11 03:53:53
问题 I find myself a bit lost on this one. I honestly can't see the error if it's just a class structure doesn't match JSON error. But I doubt it since it's the very same class structure I'm using to create the JSON. If anyone can point me in the right direction, I'd be most greateful. I've created a dotnetfiddle to avoid clutching the question with huge pieces of code. Here's the link: Fiddle I generate that JSON with a console application that gets info on the DB schema. I use a common project

Is there a javascript serializer for JSON.Net?

谁说我不能喝 提交于 2019-12-11 03:47:54
问题 I am using Newtonsoft JSON.Net to deserialize an object with PreserveReferencesHandling enabled. jQuery does not support relinking references based on the $ref and $id syntax JSON.Net uses (I don't know if jQuery supports this functionality in any capacity). I tried using Douglas Crockford's cycle.js but that does not seem to work with my objects, the returned object is identical to the object which got passed in. I am not incredibly familiar with JSON.Net, but I cannot seem to find any

How to send group separator (non printable ascii characters) with RestSharp RestClient from C#

只谈情不闲聊 提交于 2019-12-11 03:43:03
问题 Updated I have completely reworked this question and included a complete working example. My succinct question is now: How come I'm not seeing individual characters of string "\u001d" when I use RestSharp RestClient and pick json as the RequestFormat options to send a simple object to a server? I send the output to a test server, and see only 1d when I examine the output with a binary editor. I would expect 5C 75 30 30 31 64 ('\','u','0','0','1','d') AND that is what you see if you just use