json.net

Json.NET - Default deserialization behavior for a single property in CustomCreationConverter

依然范特西╮ 提交于 2019-12-12 08:30:55
问题 In the following scenario, how do I get CrazyItemConverter to carry on as usual when it encounters a JSON property that exists in the type I'm deserializing to? I have some JSON that looks like this: { "Item":{ "Name":"Apple", "Id":null, "Size":5, "Quality":2 } } The JSON gets deserialized into a class that looks a whole lot like this: [JsonConverter(typeof(CrazyItemConverter))] public class Item { [JsonConverter(typeof(CrazyStringConverter))] public string Name { get; set; } public Guid? Id

Keep json:Array attribute when converting XML to JSON to XML

旧街凉风 提交于 2019-12-12 08:30:34
问题 I have a piece of XML that looks like <person xmlns:json='http://james.newtonking.com/projects/json' id='1'> <name>Alan</name> <url>http://www.google.com</url> <role json:Array='true'>Admin</role> </person> When I try to serialize it to json string json = JsonConvert.SerializeXmlNode(xml); it ignores namespaces { "person": { "@id": "1", "name": "Alan", "url": "http://www.google.com", "role": [ "Admin" ] } } and when I deserialize it back to xml XmlDocument xml = JsonConvert.DeserializeXmlNode

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies

元气小坏坏 提交于 2019-12-12 08:27:15
问题 First, It is not just duplicate. None of answers from following questions are working for me. http://goo.gl/tS40cn http://goo.gl/pH6v2T I've just updated all my packages using Nuget Package Manager and I started receiving this error. Could not load file or assembly 'Newtonsoft.Json, Version=6.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)

Convert datetime string with this format: (yyyy-MM-dd'T'hh:mm:ss-zzz)

为君一笑 提交于 2019-12-12 08:13:09
问题 I am receiving a JSON string that contains a date that looks like this: 2015-07-09T08:38:49-07:00 where the last part is the timezone. Is there a standard way to convert this to a DateTimeOffset ? Here is what I have so far: var olu = JsonConvert.DeserializeObject<OneLoginUser>(jToken.ToString(), new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd'T'HH:mm:sszzz" }); This doesn't deserialize any of the dates. I've tried using -Z and hh:mm for the timezone data, but I can't seem to

Newtonsoft JSON for .net is ignoring jsonproperty tags

a 夏天 提交于 2019-12-12 07:26:54
问题 For some really irritating reason, the JsonProperty tags are not working with Newtonsoft's Json for .net tool. In my class I have these: [JsonProperty(PropertyName = "id")] public string ID { get; set; } [JsonProperty(PropertyName = "title")] public string Title { get; set; } [JsonProperty(PropertyName = "url")] public string Url { get; set; } [JsonProperty(PropertyName = "class")] public string EventClass { get; set; } [JsonProperty(PropertyName = "start")] public string Start { get; set; }

JSON.net Generating a lot of extra Square brackets

a 夏天 提交于 2019-12-12 06:54:02
问题 I am trying to generate the following json with JSON.Net but it is adding alot of extra square brackets with what should I do Needed Json { "addUser": { "idCard": "xxx", "firstName": "xxx", "surname": "Muscat", "isActive": true, "titleDesc": "xx", "genderDesc": "Female", "emailAddress":"", "mobileNumber":"", "telephoneNumber":"", "dob":"" } } C# code var obj = new JObject(); obj.Add( new JProperty("addUser", new JArray( new JObject( new JProperty("idCard", doct.First().idCard.PadLeft(8, '0'))

Why cant Newtonsoft.Json deserialize a Dictionary list

ぃ、小莉子 提交于 2019-12-12 06:44:33
问题 nvlst declared here then populated Dictionary<string, string> nvlst = new Dictionary<string, string>(); When the service is finished, it returns JsonConvert.SerializeObject(nvlst, Formatting.Indented) When the client attempts to deserialize, it throws an error alst = JsonConvert.DeserializeObject<Dictionary<string, string>>(sb.ToString()); here is the error message: Error converting value "{ "Status": "SUCCESS:", "CustomerId": "1", "LicenseKey": "03bad945-37c0-4fa0-8126-fb4935df396d",

Saving a toISODate gets deserialized as a non-iso string

帅比萌擦擦* 提交于 2019-12-12 06:36:43
问题 I follow the usual recommendations of serializing javascript Date objects to be sent to the server by using the toISODate js function. In fact Breeze.js is doing this for me which is great. Everything works as expected when the property on my Entity is a DateTime - the date gets saved to the database as a UTC (0 offset date) datetime. I hit a problem when the property on the Entity is of type string . A date that is sent over the wire as ' 2013-06-08T23:00:00Z ' is being deserialized into the

Parsing JSON with dynamic properties

有些话、适合烂在心里 提交于 2019-12-12 06:19:18
问题 I found an example (C# Correct way to deserialze dictionary) of how to use a Dictionary to parse json with dynamic fields. But I can't seem to get it to work on my specifc json data. I have Json data that looks like: { "status": "found", "result": { "ip_dns": { "8.8.8.8": { "fetched": 58, "found": 58, "items": { "dn1.dalebulla.com": "2012-02-25", "dns.wiseapp.net": "2014-10-16", "dns1.reachmakers.com": "2014-10-17", "dns2.xinhui.net": "2012-04-04", "dnscache2.tuxserver.net": "2014-10-17",

Deserializing ParseObjects from the Parse.NET Platform with Json.NET

蹲街弑〆低调 提交于 2019-12-12 05:49:22
问题 I'm trying to deserialize a ParseObject (as described in the parse platform developer's guide). I'm getting an error that JSON cannot deserialize that object. So I have created this: public class Phase { public string Details { get; set; } public string ObjectId { get; set; } public int PhaseId { get; set; } public bool Completed { get; set; } public string PhaseListName { get; set; } public int Position { get; set; } public int ButtonId { get; set; } } private List<ParseObject>