json.net

How to use ShouldSerialize[MemberName]() method for a property of type Object?

拜拜、爱过 提交于 2019-12-21 07:19:11
问题 I have tried to prevent the property of type object with no new values assigned to its properties using ShouldSerialize Method in Newtonsoft.Json. But I dont know how to implement it, so please help me to solve this... Here is the sample code public class Sample1 { public String name{get;set;} public int Id{get;set;}; } And this is my Class containing the above class as one of its properties public class Container { public String Cname{get;set;} public Sample1 Sample{get;set;}; public bool

Nested Json String to DataTable

你离开我真会死。 提交于 2019-12-21 06:48:33
问题 I Need to convert the following Json string to DataTable. { "pnr":"1234567890", "train_num":"12311", "train_name":"HWH DLIKLK MAI", "doj":"23-12-2013", "from_station": { "code":"DLI", "name":"Delhi" }, "to_station": { "code":"KLK", "name":"Kalka" } } In DataTable I need to Display train_num train_name doj from_station(name only) to_station(name only) What i have till now is, public class Train { public string train_num { get; set; } public string train_name { get; set; } public string doj {

JsonConvert.SerializeObject vs JsonSerializer.Serialize

时光总嘲笑我的痴心妄想 提交于 2019-12-21 05:03:06
问题 Alright I can't figure out why JsonConvert.SerializeObject serializes DateTime objects differently than JsonSerializer.Serialize. Given the class public class Test { [JsonConverter(typeof(JavaScriptDateTimeConverter))] public DateTime DeliveryDate { get { return DateTime.Now; } } } @Html.Raw(JsonConvert.SerializeObject(new Test())) outputs: "DeliveryDate": "2013-03-01T07:00:00.000Z" but when I use JsonSerializer.Serialize like in JsonNetResult: http://james.newtonking.com/archive/2008/10/16

Always have error “The ObjectContent 1 type failed to serialize the response body…”

痴心易碎 提交于 2019-12-21 04:22:14
问题 I use Web api to retrieve data from the database. I only have 1 table "tblMessage" and want to get data from that table. I set everything up but then when I run the website. the error always say The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml I read some posts on stackoverflow that sayid the error could be fixed by telling the browser to output data in json format. After that, the error becomes The 'ObjectContent`1' type failed to serialize

How to deserialize using JSON.Net to an anonymous type?

邮差的信 提交于 2019-12-21 03:41:14
问题 Just trying to create an anonymous type from JSON without knowing anything about the parameters ahead of time, and fully interpreting them (possibly with hints). i.e. that value "looks" like an int, string, or date. The only way that I know of so far is to create an anonymous type that you have pre-knowledge of. See the .DeserializeAnonymousType(...) method below. Can anyone do better than this? Thanks. var jsonString = "{\"user_id\": 1, \"user_type\": \"moderator\", \"name\": \"Fred\"}";

Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0

给你一囗甜甜゛ 提交于 2019-12-21 03:25:49
问题 I am facing the error below Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) I could see the below in Web.config <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0"

How can I read JSON from a file stored locally?

三世轮回 提交于 2019-12-20 19:57:28
问题 I am attempting to use JSON.Net to load in a JSON file stored locally on an ASP.Net MVC 4 site, but am having trouble pointing to the file. Here is what I am trying to do: List<Treatment> treatments = JsonConvert.DeserializeObject<List<Treatment>>(Server.MapPath("~/Content/treatments.json")); and am hitting this error: An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll but was not handled in user code Additional information: Unexpected character

WEB API JSON Serializing Circular References

早过忘川 提交于 2019-12-20 18:36:30
问题 I'm trying to access the property fields (JSON) from the child entity that is received from Web API. By looking at the browser console, however, it is showing a reference instead of the fields. How do I get access to these fields? ANGULAR JS VIEW <table infinite-scroll='tF.loadMore()' infinite-scroll-disabled='tF.isBusy' infinite-scroll-distance='3' class="responsive"> <thead> <tr> <th>FIELD 1</th> <th>FIELD 2</th> <th>FIELD 3</th> <th>FIELD 4</th> <th>FIELD 5</th> </tr> </thead> <tbody> <tr

WEB API JSON Serializing Circular References

时光总嘲笑我的痴心妄想 提交于 2019-12-20 18:36:22
问题 I'm trying to access the property fields (JSON) from the child entity that is received from Web API. By looking at the browser console, however, it is showing a reference instead of the fields. How do I get access to these fields? ANGULAR JS VIEW <table infinite-scroll='tF.loadMore()' infinite-scroll-disabled='tF.isBusy' infinite-scroll-distance='3' class="responsive"> <thead> <tr> <th>FIELD 1</th> <th>FIELD 2</th> <th>FIELD 3</th> <th>FIELD 4</th> <th>FIELD 5</th> </tr> </thead> <tbody> <tr

WEB API JSON Serializing Circular References

和自甴很熟 提交于 2019-12-20 18:36:00
问题 I'm trying to access the property fields (JSON) from the child entity that is received from Web API. By looking at the browser console, however, it is showing a reference instead of the fields. How do I get access to these fields? ANGULAR JS VIEW <table infinite-scroll='tF.loadMore()' infinite-scroll-disabled='tF.isBusy' infinite-scroll-distance='3' class="responsive"> <thead> <tr> <th>FIELD 1</th> <th>FIELD 2</th> <th>FIELD 3</th> <th>FIELD 4</th> <th>FIELD 5</th> </tr> </thead> <tbody> <tr