json.net

Mongo DB object Id deserializing using JSON serializer

∥☆過路亽.° 提交于 2020-01-19 16:23:08
问题 var docToJson = doc.ToJson<BsonDocument>(); story Featured = JsonConvert.DeserializeObject<story>(docToJson); public class story { [JsonProperty("_id"), JsonConverter(typeof(ObjectIdConverter))] public ObjectId Id { get; set; } .... public class ObjectIdConverter : JsonConverter { public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { serializer.Serialize(writer, value.ToString()); } public override object ReadJson(JsonReader reader, Type objectType,

JSON deserialize to constructed protected setter array

久未见 提交于 2020-01-19 15:43:09
问题 I use Newtonsoft JSON to serialize/deserialize my objects. One of those contains an array with a protected setter because the constructor build the array itself and only the members are manipulated. This can be serialized without problem but when it comes to deserialization the property it is ignored because it is not public. I tried a custom converter with it is also not called because it is not public. This is a minimized example: public static class TestCoordsDeserialization { private

Remove specific properties from JSON object

落爺英雄遲暮 提交于 2020-01-19 13:10:27
问题 I have a JSON: { "scbs_currentstatus": "", "scbs_primaryissue": "", "_umb_id": "Test", "_umb_creator": "Admin", "_umb_createdate": "0001-01-01 00:00:00", "_umb_updatedate": "0001-01-01 00:00:00", "_umb_doctype": "Test", "_umb_login": "Test", "_umb_email": "Test", "_umb_password": { "newPassword": "Test", "oldPassword": null, "reset": null, "answer": null }, "_umb_membergroup": { " User": false, "Line User": true, "Callback User": false, "Su User": false, }, "umbracoMemberComments": "Test",

Remove specific properties from JSON object

女生的网名这么多〃 提交于 2020-01-19 13:10:08
问题 I have a JSON: { "scbs_currentstatus": "", "scbs_primaryissue": "", "_umb_id": "Test", "_umb_creator": "Admin", "_umb_createdate": "0001-01-01 00:00:00", "_umb_updatedate": "0001-01-01 00:00:00", "_umb_doctype": "Test", "_umb_login": "Test", "_umb_email": "Test", "_umb_password": { "newPassword": "Test", "oldPassword": null, "reset": null, "answer": null }, "_umb_membergroup": { " User": false, "Line User": true, "Callback User": false, "Su User": false, }, "umbracoMemberComments": "Test",

Newtonsoft is not serializing navigation property

天涯浪子 提交于 2020-01-17 07:19:44
问题 I have an EF object RetailDocuments . It is related to the DocumentTemplateMaster object via foreign key. Many RetailDocuments can have the same DocumentTemplateMaster . I'm retrieving a List<RetailDocument> and have turned off proxy creation and lazy loading. The referenced DocumentTemplateMaster object is there in the List but not when it is serialized. I've tried a number of solutions I've seen here on SO and other places but for whatever reason, it's not working for me. Here's my code,

Parsing huge Json files having multiple json objects using json.net [duplicate]

别等时光非礼了梦想. 提交于 2020-01-17 06:19:12
问题 This question already has answers here : Deserialize json array stream one item at a time (4 answers) Closed 4 years ago . I would like to know if there is a way to read one json object at a time using Json.net. Currently, here is the code I'm using which works but loads the whole file in the streamreader but not able to just parse one object at a time. any suggestions?? StreamReader streamReader = new StreamReader(@"Sample.json"); List<Member> mlist; using (JsonReader reader = new

Convert Int to String while serialize object using JSON.NET

江枫思渺然 提交于 2020-01-17 05:30:10
问题 I tried to convert DataTable to JSON string using JObject (NewtonSoft.dll). In my case table may have values with different data types. I want to convert those values to string while serialize the object. DataTable tab = new DataTable(); tab.Columns.Add("ID", typeof(int)); tab.Columns.Add("Name"); tab.Rows.Add(1, "Role1"); tab.Rows.Add(2, "Role2"); string strValues = JsonConvert.SerializeObject(tab); --output of strValues -- [{"ID":1,"Name":"Role1"},{"ID":2,"Name":"Role2"}] But it should be

an easy way to serialise c# objects

不问归期 提交于 2020-01-17 03:14:14
问题 I'm using Newtonsoft.Json to turn json into objects, that works fine. I was wondering if there's a nice way to reverse the process noting that i dont want to jsonise all the object fields. To paraphrase, is there a way to use Newtonsoft.Json to produce thinned down jsonised object representations? 回答1: Have you tried using the JsonIgnore to opt-out properties that you don't want to be included in the JSON serialization? See this topic: http://james.newtonking.com/projects/json/help

JsonConvert DeserializeObject error in c#

柔情痞子 提交于 2020-01-16 15:43:27
问题 I have the following model public class UserSettings { public bool SendEmailAlertsForNewArticlesOrReports { get; set; } public bool ShowNotificationsInCubeBrowserForArticlesAndReports { get; set; } } I serialize it like this string sUserSettings = JsonConvert.SerializeObject(userSettings); It stores this in the backend "{\"SendEmailAlertsForNewArticlesOrReports\":false,\"ShowNotificationsInCubeBrowserForArticlesAndReports\":true}" When I am trying to deserialize it like this UserSettings

JsonConvert DeserializeObject error in c#

巧了我就是萌 提交于 2020-01-16 15:43:25
问题 I have the following model public class UserSettings { public bool SendEmailAlertsForNewArticlesOrReports { get; set; } public bool ShowNotificationsInCubeBrowserForArticlesAndReports { get; set; } } I serialize it like this string sUserSettings = JsonConvert.SerializeObject(userSettings); It stores this in the backend "{\"SendEmailAlertsForNewArticlesOrReports\":false,\"ShowNotificationsInCubeBrowserForArticlesAndReports\":true}" When I am trying to deserialize it like this UserSettings