json.net

Two different versions of Newtonsoft.Json.dll needed in ASP.NET MVC

好久不见. 提交于 2020-02-23 12:43:37
问题 I have developed a MVC application that has dependency on Connectwise SDK that uses Newtonsoft.Json.dll v6.0.0.0 and Dropbox SDK that uses Newtonsoft.Json.dll v7.0.0.0. I need to ensure that my project uses the appropriate dll when needed. After researching, I tried the following: - Placed the 2 dlls under sub-folders /dlls/6.0.0.0/ and /dlls/7.0.0.0 resp. - Referenced version 6.0.0.0 dll in project References - Added to web.config <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

Two different versions of Newtonsoft.Json.dll needed in ASP.NET MVC

▼魔方 西西 提交于 2020-02-23 12:42:52
问题 I have developed a MVC application that has dependency on Connectwise SDK that uses Newtonsoft.Json.dll v6.0.0.0 and Dropbox SDK that uses Newtonsoft.Json.dll v7.0.0.0. I need to ensure that my project uses the appropriate dll when needed. After researching, I tried the following: - Placed the 2 dlls under sub-folders /dlls/6.0.0.0/ and /dlls/7.0.0.0 resp. - Referenced version 6.0.0.0 dll in project References - Added to web.config <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

How to check if object is JProperty or JArray

我的梦境 提交于 2020-02-21 11:04:31
问题 Given the two JTokens: { "Users": { "Name": "Carl" } } and { "Users": [ { "Name": "Carl" }, {"Name": "Peter"} ] } How can I tell if Users is a JProperty or JObject/JArray? I need loop Users with foreach (JObject User in myjobject["Users"]) { ... } Solution It was as simple as myjobject["Users"].GetType(). However, that didn't work in the Watch debugger window, but it worked at runtime. Hrmpff. 回答1: The Type property will tell you the type of the token you have. switch(token.Type) { case

Can I instruct Json.NET to deserialize, but not serialize, specific properties? [duplicate]

我的梦境 提交于 2020-02-19 09:50:08
问题 This question already has answers here : Making a property deserialize but not serialize with json.net (10 answers) Closed 4 years ago . I have an AngularJS + MVC 5 + Web API 2 app that allows users to manage collections of objects in the browser and commit all changes at once when a Save button is clicked. As changes are made, one or more properties are added to the JavaScript objects: IsAdded, IsUpdated, IsRemoved. The properties are checked server-side to determine what to do when

Deserialize json character as enumeration

泄露秘密 提交于 2020-02-19 07:30:06
问题 I have an enumeration defined with C#, where I'm storing it's values as characters, like this: public enum CardType { Artist = 'A', Contemporary = 'C', Historical = 'H', Musician = 'M', Sports = 'S', Writer = 'W' } I'm attempting to deserialize using JSON.NET, but the incoming JSON was written using the CHAR value (string) instead of the int value of the enumeration, like this: [{"CardType","A"},{"CardType", "C"}] Is it possible to define some kind of converter that will allow me to manually

Deserialize json character as enumeration

点点圈 提交于 2020-02-19 07:29:49
问题 I have an enumeration defined with C#, where I'm storing it's values as characters, like this: public enum CardType { Artist = 'A', Contemporary = 'C', Historical = 'H', Musician = 'M', Sports = 'S', Writer = 'W' } I'm attempting to deserialize using JSON.NET, but the incoming JSON was written using the CHAR value (string) instead of the int value of the enumeration, like this: [{"CardType","A"},{"CardType", "C"}] Is it possible to define some kind of converter that will allow me to manually

JsonIgnore attribute keeps serializing properties in ASP.NET Core 3

让人想犯罪 __ 提交于 2020-02-13 20:37:01
问题 I've recently updated my API project to ASP.NET Core 3. Since then, [JsonIgnore] attributes are not working: public class Diagnostico { [JsonIgnore] public int TipoDiagnostico { get; set; } [JsonIgnore] public int Orden { get; set; } [JsonIgnore] public DateTime? FechaInicio { get; set; } public string TipoCodificacion { get; set; } public string Codigo { get; set; } public string Descripcion { get; set; } } All the properties of classes are being serialized. The API endpoints are in .NET

JsonIgnore attribute keeps serializing properties in ASP.NET Core 3

空扰寡人 提交于 2020-02-13 20:34:07
问题 I've recently updated my API project to ASP.NET Core 3. Since then, [JsonIgnore] attributes are not working: public class Diagnostico { [JsonIgnore] public int TipoDiagnostico { get; set; } [JsonIgnore] public int Orden { get; set; } [JsonIgnore] public DateTime? FechaInicio { get; set; } public string TipoCodificacion { get; set; } public string Codigo { get; set; } public string Descripcion { get; set; } } All the properties of classes are being serialized. The API endpoints are in .NET

Add a new entry to the json file

别等时光非礼了梦想. 提交于 2020-02-06 16:14:07
问题 I have a JSON file with the following format: { "profiles": { "Profile1": { "name": "Nombre 1", "lastVersionId": "14.23.5.2838", "javaArgs": "-Xmx8G" }, "Profile2": { "name": "Nombre 2", "lastVersionId": "58.96.004", "javaArgs": "-Xmx8G" } }, "selectedProfile": "Profile1" } I need to add a new profile, that is, add this entire block: "Profile3": { "name": "Nombre 3", "lastVersionId": "58.96.004", "javaArgs": "-Xmx8G" } I forgot to say that I don't know all the fields of JSON, therefore, I can

Newtosoft Json Deserialization: How to throw an error if/when the given json string has MORE properties than necessary?

折月煮酒 提交于 2020-02-05 05:31:32
问题 Assuming we have the following class: public class Foo { public long Id { get; set; } } How can we tell newtonsoft json to throw a tantrum if a given json-string is: { "Id": 10, "SomethingIrrelevant": "Foobar" } In other words we want the deserialization to be ultra-strict and throw a tantrum when it detects anything fishy of this sort taking place. 回答1: Use MissingMemberHandling.Error for your JsonSerializerSettings : var deserialized = JsonConvert.DeserializeObject<Foo>(jsonString, new