json.net

Internet Explorer, Json.Net JavaScript date and milliseconds issue

非 Y 不嫁゛ 提交于 2019-12-18 15:55:26
问题 I'm not sure if it's me missing something - or IE or Json.Net. But basically this works: new Date("2012-08-03T12:36:54.743Z") This fails with 'Invalid Date' error: new Date("2012-08-03T12:36:54.74Z") The second date is stored in SQL Server as: 2012-08-03 12:36:54.740 It is then serialised as JSON using Json.Net - Json.Net did serialised the date as 2012-08-03T12:36:54.74Z , effectively chopping off the last 0. My question(s): Is this an intended behavior in IE - that it needs to have all 3

Internet Explorer, Json.Net JavaScript date and milliseconds issue

↘锁芯ラ 提交于 2019-12-18 15:55:16
问题 I'm not sure if it's me missing something - or IE or Json.Net. But basically this works: new Date("2012-08-03T12:36:54.743Z") This fails with 'Invalid Date' error: new Date("2012-08-03T12:36:54.74Z") The second date is stored in SQL Server as: 2012-08-03 12:36:54.740 It is then serialised as JSON using Json.Net - Json.Net did serialised the date as 2012-08-03T12:36:54.74Z , effectively chopping off the last 0. My question(s): Is this an intended behavior in IE - that it needs to have all 3

How to deserialize class without calling a constructor?

孤街醉人 提交于 2019-12-18 14:14:54
问题 I'm using Json.NET in my WCF data service. Here's my class (simplified): [DataContract] public class Component { public Component() { // I'm doing some magic here. } } How can I deserialize that class without invoking a constructor using JsonConvert.DeserializeObject ? Sorry if not clear, feel free to ask questions. 回答1: You could create a class that inherits from CustomCreationConverter and use FormatterServices.GetSafeUninitializedObject to create your object. It skips calling the

Overriding a property value in custom JSON.net contract resolver

旧城冷巷雨未停 提交于 2019-12-18 13:27:45
问题 I am attempting to implement a custom JSON.net IContractResolver that will replace all null property values with a specified string. I'm aware that this functionality is available via attributes on member of types that get serialized; this is an alternative route that we're considering. My resolver implementation so far is as follows. StringValueProvider is a simple implementation of IValueProvider that doesn't affect the problem, which is that I can't figure out how to get the value of

How to default a null JSON property to an empty array during serialization with a List<T> property in JSON.NET?

回眸只為那壹抹淺笑 提交于 2019-12-18 13:23:28
问题 Currently I have JSON that either comes in via an HTTP call or is stored in a database but during server processing they are mapped to C# objects. These objects have properties like public List<int> MyArray . When the JSON contains MyArray:null I want the resulting property to be an empty List<T> instead of a null List<T> property. The goal is that the object will "reserialize" to JSON as MyArray:[] , thus either saving to the database or responding out via HTTP as an empty array instead of

How to Serialize XML to a JSON object with Json.NET

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 13:22:17
问题 I can serialize XML to a JSON string like this: var xml = new XmlDocument(); xml.LoadXml("<person><name>John</name></person>"); string jsonString = Newtonsoft.Json.JsonConvert.SerializeXmlNode(xml, Newtonsoft.Json.Formatting.None); Response.ContentType = "application/json"; Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(jsonString)); That would give me: "{\"person\":{\"name\":\"John\"}}" But how can I serialize it to a JSON object? Like this: {"person":{"name":"John"}} 回答1:

How to serialize enums to different property name using json.net

倖福魔咒の 提交于 2019-12-18 12:57:07
问题 I have the following enum public enum PermissionType { [JsonProperty(PropertyName = "can_fly")] PermissionToFly, [JsonProperty(PropertyName = "can_swim")] PermissionToSwim }; and a class with this property [JsonProperty(PropertyName = "permissions", ItemConverterType = typeof(StringEnumConverter))] public IList<PermissionType> PermissionKeynames { get; set; }` I want to serialize the list of enumerations to a list of strings, and that serialize list use the string specified in PropertyName

JsonConvert.DeserializeObject could not convert string to DateTime when using non-us date formats

谁说我不能喝 提交于 2019-12-18 12:46:37
问题 I have the following serialized json object: "{\"LineItems\":[{\"LineID\":1,\"QuoteID\":\"00000000-0000-0000-0000-000000000000\",\"Quantity\":\"1\",\"UnitPriceExTax\":\"2\",\"UnitPriceTaxRate\":\"2\",\"UnitPriceTaxAmt\":0,\"LineTotalExTax\":2,\"LineTotalTaxAmt\":0.040000000000000036,\"LineTotalIncTax\":2.04}],\"QuoteID\":[],\"CurrencyID\":\"2\",\"SupplierRef\":\"SDFSFSDF\",\"DeliveryDate\":\"22/02/2014\",\"QuoteAvailablityStartDate\":\"13/02/2014\",\"QuoteAvailablityEndDate\":\"09/02/2014\",\

Deserialize complex JSON object using c#

断了今生、忘了曾经 提交于 2019-12-18 09:49:33
问题 I know how to deserialize basic Json object. I am having a problem with nested objects; for example, here is an example json i want to deserialize. { "data": { "A": { "id": 24, "key": "key", "name": "name", "title": "title" }, "B": { "id": 37, "key": "key", "name": "name", "title": "title" }, "C": { "id": 18, "key": "key", "name": "name", "title": "title" }, "D": { "id": 110, "key": "key", "name": "name", "title": "title" } }, "type": "type", "version": "1.0.0" } Now "data" has an unknown

How to Deserialize JSON data? C#

点点圈 提交于 2019-12-18 09:43:29
问题 Im getting a Json Data from an API and i have been trying to deserialize. Json data: { "items": [ { "id": "1", "name": "samplename", "AddressList1": { "City": "Hyd", "State": "TN", "Country": "IN" }, "Age": "10" }, { "id": "2", "name": "samplename2", "AddressList1": { "City": "Hydd", "State": "TN", "Country": "IN" }, "Age": "10" } ], "paging": { "cursors": {} } } Entities: public class AddressList1 { public string City { get; set; } public string State { get; set; } public string Country {