json.net

Using custom JsonConverter in order to alter the serialization of the portion of an object

南楼画角 提交于 2019-12-10 20:32:54
问题 I'm having a hard time overriding the WriteJson method of a custom JsonConverter in order to slightly alter the way serialization is performed. I need to call a REST service that accepts a certain input that has a generic portion. I can reproduce the problem I'm having with the following payload format : public sealed class JsonField { public string Key { get; set; } public object Value { get; set; } public string OtherParam { get; set; } } public sealed class JsonPayload { public string

JsonSerializationException Parsing

耗尽温柔 提交于 2019-12-10 20:18:14
问题 I'm trying to wrap my application with some graceful exception handling. When my app fails to deserialize JSON, I get a JsonSerializationException that has a Message that looks like this: Error converting value "[IncorrectDataType]" to type 'ApexFramework.Enums+DataTypes'. Path 'Layout[0].ElementContainer[0].ContainerDatatype', line 12, position 58. From this exception message, I am interested in capturing and presenting in a clean manner the following: I need the Index of the Element

ServiceStack.Text serialize circular references

ⅰ亾dé卋堺 提交于 2019-12-10 19:59:38
问题 I need to serialize an object graph like this: public class A { public B Link1 {get;set;} } public class B { public A Link2 {get;set;} } So that the json only gets two instances, but is deserialized correctly again. E.g. using a meta Id or something similiar. I know that there is a way in Json.NET as described here: http://note.harajuku-tech.org/serializing-circular-references-with-jsonnet with meta ids. Is there a similiar feature in ServiceStack.Text Json Serializer? Otherwise, is it

Segmentation fault using newtonsoft json in linux with mono

白昼怎懂夜的黑 提交于 2019-12-10 19:55:11
问题 Running Mono 3.2.6 on Debian 7 When using Newtonsoft.Json to deserialize objects in a multithreaded application, my application crashes due to 'segmentation fault.' I attached gdb & here's the output: root@ns38225:/home/stress# gdb program 30380 GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the

Convert a JObject to a strongly typed object

前提是你 提交于 2019-12-10 19:44:40
问题 I'm using JsonConvert to serialize and deserialize objects from classes like this: public class DbBulkRequest { public DbEntity[] Updates { get; set; } } public class DbEntity { public string Name { get; set; } public object Dto { get; set; } } When I deserialize Dto , I get an object of type JObject . At the time of deserialization, I want to create strongly typed objects based on Dto . I can create the objects; however, I don't know of a good way of populating their properties. The best I

Circular reference exception when serializing an object containing a JToken to XML in Web API

做~自己de王妃 提交于 2019-12-10 19:39:22
问题 In my database, I have a table with lots of columns and one of them contains a JSON string (I have no control over this). Something like this: Name Age ExtraData ---- --- ------------------ Bob 31 {c1: "1", c2: "2"} <-- string with JSON My Web API endpoint must return XML or JSON depending on the Accept headers in the request. Something like this: JSON: { "Name": "Bob", "Age": 31, "ExtraData": { "c1": 1, "c2": 2 } } XML: <person> <Name>Bob</Name> <Age>31</Age> <ExtraData> <c1>1</c1> <c2>2</c2

Error deserializing JSON Cannot deserialize JSON object into type 'System.String'

谁说我不能喝 提交于 2019-12-10 19:35:57
问题 I have the following JSON: {"workspace": { "name":"Dallas", "dataStores":"http://.....:8080/geoserver/rest/workspaces/Dallas/datastores.json", "coverageStores":"http://.....:8080/geoserver/rest/workspaces/Dallas/coveragestores.json", "wmsStores":"http://....:8080/geoserver/rest/workspaces/Dallas/wmsstores.json"}} And I´m trying to deserialize int this class: class objSON { public string workspace { get; set; } public string name { get; set; } public string dataStores { get; set; } public

conditionally ignore property serialization

﹥>﹥吖頭↗ 提交于 2019-12-10 19:22:42
问题 I have a Asp.Net WebApi project and I want to return a list of product in Json format and one specific product. This is my product model: public class Product { public int Id { get; set; } public string ShortString { get; set; } public string LongString { get; set; } } And this is my ApiController: public class ProductController : ApiController { public IQueryable<Product> Get() { return Context.Products; } public IHttpActionResult Get(int id) { var p = Context.Products.FirstOrDefault(m => m

Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies

三世轮回 提交于 2019-12-10 19:12:10
问题 This one error is driving me nuts. I installed the SendGrid NuGet package in one of my class libraries named BaseServices , which has a dependency on Newtonsoft.Json v7.0.1 , so it installs that in my packages folder and references that. In the class library, I have this binding redirect: <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> </dependentAssembly>

json.NET throwing an InvalidCastException deserializing a 2D array

半世苍凉 提交于 2019-12-10 19:05:28
问题 I'm attempting to deserialize a 2 dimensional array of double values from a json string. The following code replicates my problem: using Newtonsoft.Json; using Newtonsoft.Json.Linq; // Here is the json string I'm deserializing: string json = @"{ ""array2D"": [ [ 1.2120107490162675, -0.05202334010360783, -0.9376574575207149 ], [ 0.03548978958456018, 1.322076093231865, -4.430964590987738 ], [ 6.428633738739363e-05, -1.6407574756162617e-05, 1.0 ] ], ""y"": 180, ""x"": 94 }"; // Here is how I