json.net

Model to match this JSON for deserialization, field names with dashes

点点圈 提交于 2019-12-11 01:20:08
问题 I am trying to create a model that would match the JSON.NET deserealization of this JSON structure: First item... { "190374": { "vid": 190374, "canonical-vid": 190374, "portal-id": 62515, "is-contact": true, "profile-token": "AO_T-mN1n0Mbol1q9X9UeCtRwUE1G2GFUt0VVxCzpxUF1LJ8L3i75x9NmhIiS0K9UQkx19bShhlUwlIujY4pSXAFPEfDG-k9n8BkbftPw6Y5oM3eU5Dc_Mm-5YNJTXiWyeVSQJAN_-Xo", "profile-url": "https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T

F# record with option field doesn't deserialize properly in Asp.Net WebApi 2.x app

落爺英雄遲暮 提交于 2019-12-11 01:19:09
问题 I have a C# Asp.Net MVC (5.2.7) app with support for WebApi 2.x targeting .Net 4.5.1. I am experimenting with F# and I added an F# library project to the solution. The web app references the F# library. Now, I want to be able to have the C# WebApi controller return F# objects and also save F# objects. I have trouble serializing a F# record with an Option field. Here is the code: C# WebApi controller: using System; using System.Collections.Generic; using System.Linq; using System.Net; using

A Generlized XML serializer but not working on JObject

假装没事ソ 提交于 2019-12-11 01:03:38
问题 I have a function which serializes any object into xml. private string ConvertToXml(object obData) { var x = new System.Xml.Serialization.XmlSerializer(obData.GetType()); var myStr = string.Empty; try { using (var ms = new MemoryStream()) { x.Serialize(ms, obData); ms.Position = 0; var sr = new StreamReader(ms); myStr = sr.ReadToEnd(); _log.DebugFormat("Converted XML output of record:: {0}", myStr); } } catch (Exception e) { _log.WarnFormat("Object Conversion to XML Document Failed ..{0} and

Change the way JSON.NET serializes property names

。_饼干妹妹 提交于 2019-12-11 00:25:18
问题 How can I change the way Newtonsoft JSON.NET serializes property names of objects? 回答1: A couple of ways: You can manually control how it serializes using the JsonTextWriter class: http://james.newtonking.com/projects/json/help/index.html?topic=html/ReadingWritingJSON.htm You could implement a custom JsonConverter that does what you want: http://james.newtonking.com/projects/json/help/index.html?topic=html/T_Newtonsoft_Json_JsonConverter.htm Example: JSON.NET customizing the serialization to

Json.net deserialization is returning an empty object

寵の児 提交于 2019-12-11 00:24:16
问题 I'm using the code below for serialization. var json = JsonConvert.SerializeObject(new { summary = summary }); summary is a custom object of type SplunkDataModel : public class SplunkDataModel { public SplunkDataModel() {} public string Category { get; set; } public int FailureCount { get; set; } public Dictionary<string, SplunkError> FailureEntity { get; set; } public Dictionary<string, string> JobInfo { get; set; } public string JobStatus { get; set; } public int SuccessCount { get; set; }

Json.NET validate JSON array against Schema

拥有回忆 提交于 2019-12-11 00:14:19
问题 I want to validate a schema which has an array, all in one call to the validate method. I did it in javascript but I am sturggling to do it in C# with Json.NET. With Json.NET I am calling the validation method for each object in the array like so: JSchema schema = JSchema.Parse(@"{ 'title': 'HouseCollection', 'description': '', '$schema': 'http://json-schema.org/draft-04/schema#', 'definitions': { 'Categories': { 'title': 'Categories', 'description': '', '$schema': 'http://json-schema.org

Store/retrieve child-parent relationship with JsonConverter

三世轮回 提交于 2019-12-10 23:52:30
问题 I have a JSON structure (including POCO classes) with child-objects arrays like this: "Object": [ { "Name": "TestA", "ChildObjects": [ { "Name": "TestB" "ChildObjects": [ { "Name": "TestC" ... } ] } ] When deserializing, I would like to keep a reference to the parent object I've just created. But I must get this reference before populating the child-object.(On the moment that I populate the child-object I must have the parent-object structure/reference accessible) . I've tried using a custom

JSON tree modifications that don't break “$ref” references

安稳与你 提交于 2019-12-10 23:51:54
问题 Question relates to JSON which is result of serialization with PreserveReferencesHandling set to PreserveReferencesHandling.Objects . I'm looking for clever way for modifying a branch of JSON tree (removing or replacing branch in particular) so that references handling is not broken. Consider following JSON: { "OuterGroup": { "ElementA": { "$id": "1", "data": "A" }, "ElementB": { "$id": "2", "data": "B" } }, "OuterElement": { "$ref": "1" } } I need to replace or remove ElementA. If I do it by

How to escape embedded JSON after unescape

三世轮回 提交于 2019-12-10 23:46:33
问题 When serializing with Json.NET, I need to escape embedded JSON after previously unescaping while deserializing. Which means I unescaped following JSON according to this post. Here is my JSON: { "Message":null, "Error":false, "VData":{ "RNumber":null, "BRNumber":"Session1" }, "onlineFields":{ "CCode":"Web", "MNumber":"15478655", "Product":"100", "JsonFile":" { \"evaluation\":{ \"number\":[ { \"@paraID\":\"1000\", \"@Value\":\"\", \"@label\":\"We are america\" }, { \"@paraID\":\"2000\", \"

JSON.net - Write into JSON / JObject using path string

﹥>﹥吖頭↗ 提交于 2019-12-10 23:33:53
问题 I have a little utility where we extract values from JSON using JObject.SelectToken(path) . We need to determine the paths at run-time. Works perfectly. What I now need to do is to write back into the JSON (JObject or other) using the same path string. I've hunted and searched and I can't quite find if there is anything that does this quite as cleanly as SelectToken does for reading. (I'm also stuck in 3.5 CF) For example, something like: ... JObject read in already ... var theJToken =