json.net

Json.NET + VerificationException Operation could destabilize the runtime

独自空忆成欢 提交于 2020-01-30 04:12:15
问题 I am getting the "Operation could destablize the runtime exception". I goggled quite a bit, looks like exception has to do with conflicting assemblies being loaded at runtime. So, here are couple of things the same source code works in my colleagues machine. I looked and searched for each reference to NewtonSoft.Json.dll and it seems like its coming from a same assembly. (I think this would not be a problem as it is working in other people machine). I am using Raven which references

convert complex json to c# class

不打扰是莪最后的温柔 提交于 2020-01-29 16:42:27
问题 I have been trying to deserialize the following json data into classes for 2 days using the help from similar questions on this and other sites, and might possibly be going brain dead. I have this json data (apologies for length) and am trying, as a start to get the 'value' number in the 'Values' array:- { "metadata": { "columnGrouping": [ "area", "metricType", "period", "valueType" ], "rowGrouping": [] }, "columns": [ { "area": { "identifier": "E31000040", "label": "Gtr Manchester Fire",

Deserialize JSON recursively to IDictionary<string,object> [duplicate]

試著忘記壹切 提交于 2020-01-27 06:19:33
问题 This question already has answers here : How do I use JSON.NET to deserialize into nested/recursive Dictionary and List? (5 answers) Closed 4 years ago . I'm trying to convert some older work to use Newtonsoft JSON.NET. The default handling using the System.Web.Script.Serialization.JavaScriptSerializer.Deserialize method (e.g. if no target type is specified) is to return a Dictionary<string,object> for inner objects. This is actually a really useful basic type for JSON since it also happens

Deserialize JSON recursively to IDictionary<string,object> [duplicate]

淺唱寂寞╮ 提交于 2020-01-27 06:15:46
问题 This question already has answers here : How do I use JSON.NET to deserialize into nested/recursive Dictionary and List? (5 answers) Closed 4 years ago . I'm trying to convert some older work to use Newtonsoft JSON.NET. The default handling using the System.Web.Script.Serialization.JavaScriptSerializer.Deserialize method (e.g. if no target type is specified) is to return a Dictionary<string,object> for inner objects. This is actually a really useful basic type for JSON since it also happens

Deserialize JSON recursively to IDictionary<string,object> [duplicate]

試著忘記壹切 提交于 2020-01-27 06:14:00
问题 This question already has answers here : How do I use JSON.NET to deserialize into nested/recursive Dictionary and List? (5 answers) Closed 4 years ago . I'm trying to convert some older work to use Newtonsoft JSON.NET. The default handling using the System.Web.Script.Serialization.JavaScriptSerializer.Deserialize method (e.g. if no target type is specified) is to return a Dictionary<string,object> for inner objects. This is actually a really useful basic type for JSON since it also happens

Doesn't ASP.NET Web Api Model Binding Use Newtonsoft (JSON.NET)

本小妞迷上赌 提交于 2020-01-26 00:59:46
问题 As far as I understand, Web Api uses Newtonsoft (JSON.NET) serializer/deserializer when model binding. But when I use [JsonProperty(Required = Required.AllowNull)] attribute for a model property, it does not work. I omit the property in JSON but model binder does not throw exception or make the ModelState.IsValid false. My questions are: Why does it not work if Web Api is using Json.Net? Is there a simple solution like a configuration change? If I have to use a custom model binder in order to

Serialize specific property of object's property/field with JSON.NET

限于喜欢 提交于 2020-01-25 22:05:01
问题 Suppose I have these two classes Book public class Book { [JsonProperty("author")] [---> annotation <---] public Person Author { get; } [JsonProperty("issueNo")] public int IssueNumber { get; } [JsonProperty("released")] public DateTime ReleaseDate { get; } // other properties } and Person public class Person { public long Id { get; } public string Name { get; } public string Country { get; } // other properties } I want to serialize Book class to JSON , but instead of property Author

Serialize specific property of object's property/field with JSON.NET

血红的双手。 提交于 2020-01-25 22:04:28
问题 Suppose I have these two classes Book public class Book { [JsonProperty("author")] [---> annotation <---] public Person Author { get; } [JsonProperty("issueNo")] public int IssueNumber { get; } [JsonProperty("released")] public DateTime ReleaseDate { get; } // other properties } and Person public class Person { public long Id { get; } public string Name { get; } public string Country { get; } // other properties } I want to serialize Book class to JSON , but instead of property Author

Loop through returned JSON from an API

£可爱£侵袭症+ 提交于 2020-01-25 21:25:08
问题 I have the following JSON in asp.net VB: Dim jsonString As String = "{'results':[ {'comments': 'some text', 'date' : 'some date', 'user':'aaa'},{'comments': 'some text2', 'date2' : 'some date2', 'user':'aaa2'}]} " Dim json As JObject = JObject.Parse(jsonString) How can I loop though the values like comments? Thank you 回答1: The Newtonsoft documentation pages Querying JSON with LINQ and Querying JSON with SelectToken describe how you can query for values nested inside a JObject hierarchy once

How to read and iterate JSON file contents?

自闭症网瘾萝莉.ら 提交于 2020-01-25 12:49:05
问题 This is my JSON file. { "webroot": "wwwroot", "version": "1.0.0-*", "dependencies": { "EntityFramework.SqlServer": "7.0.0-beta5", "EntityFramework.Commands": "7.0.0-beta5", "Microsoft.AspNet.Mvc": "6.0.0-beta5", }, "exclude": [ "wwwroot", "node_modules", "bower_components" ], } I can read value of "webroot" as string and "exclude" as array using following snippet. string file = File.ReadAllText("project.json"); Product pro = JsonConvert.DeserializeObject<Product>(file); But I cannot read the