json.net

DateTime column type becomes String type after deserializing DataTable

时光怂恿深爱的人放手 提交于 2021-01-29 14:55:20
问题 I have a DataTable having two columns. ShipmentDate(DateTime) and Count(Int). after I deserialize the string I noticed the type of ShipmentDate becomes string if the first itemarray value is null. Check the below example. both the json string have same data except the first array item. string jsonTable1 = "[{\"ShipmentDate\":null,\"Count\":3},{\"ShipmentDate\":\"2015-05-13T00:00:00\",\"Count\":13},{\"ShipmentDate\":\"2015-05-19T00:00:00\",\"Count\":1},{\"ShipmentDate\":\"2015-05-26T00:00:00\"

How can I change Serialization approach (Typed,None) for some actions in Asp.Net Core?

我与影子孤独终老i 提交于 2021-01-29 11:10:51
问题 I have asp.net core 2.2 web Application. The application contains Command and Query Actions, Command Actions must return typed json response: { $type:"A.B.Customer, x.dll ", id: 11231, name: "Erwin .." } Query Actions must return non typed response: { id: 34234, name: "Erwin .. " } We can choose one outputformatter for Json responses at startup. services.AddMvc().AddJsonOptions(o => { SerializerSettings.TypeNameHandling=Newtonsoft.Json.TypeNameHandling.Objects // SerializerSettings

How to deserialize a JSON array of elements with different types and varying number of elements?

倖福魔咒の 提交于 2021-01-29 09:50:37
问题 I am dealing with a JSON array, where each element is of a different type, indicated by a type attribute. There can be more than one element of the same type, and the number of elements is not known beforehand. That is: [ { 'abc': '0', 'type': 'a' }, { 'cde': '10', 'type: 'b' }, { 'abc': '20' 'type': 'a' } ] I need to deserialize such an array into a List<A> and List<B> . I looked into Json.NET documentation but I am not sure what would be a good strategy or feature to use for this task. Any

How to deserialize complex json from class that have unknown number of properties

ぃ、小莉子 提交于 2021-01-29 07:59:44
问题 I have complex json and problem getting data from it. I need to display daily currency, but I am not sure how to get data from TimeSeriesDigitalCurrencyDaily class. TimeSeriesDigitalCurrencyDaily class can have N number of properties. How to get rid of "__invalid_type__20171214153500 __invalid_name__2017-12-14 15:35:00" and have proper name for this and all others properties? public class MetaData { public string __invalid_name__1. Information { get; set; } public string __invalid_name__2.

How do I get all the fields using json.net?

偶尔善良 提交于 2021-01-29 04:55:39
问题 A third party is giving me something similar to the below. When I know the key (such as easyField ) getting the value is easy. Below I write it in the console. However the third party gave me json that uses random keys. How do I access it? { var r = new Random(); dynamic j = JsonConvert.DeserializeObject(string.Format(@"{{""{0}"":""hard"", ""easyField"":""yes""}}", r.Next())); Console.WriteLine("{0}", j["easyField"]); return; } 回答1: You can use reflection with JSON.NET! It will give you the

JSON Deserialize Object HTTPWebResponse

妖精的绣舞 提交于 2021-01-29 03:56:01
问题 I am trying to take my Web Request JSON output and parse it. Here is the output { "kind":"internal", "name":"SplashPageToggle_dg", "fullPath":"SplashPageToggle_dg", "generation":1255326, "selfLink":"https://link", "type":"stri ng", "records":[ { "name":"enable_app1", "data":"0" }, { "name":"enable_app2", "da ta":"0" }, { "name":"enable_app3", "data":"0" }, { "name":"enable_app4", "data":"0" }, { "name":"enable_app5", "data":"0" }, { "name":"enable_app6", "data":"1" }, { "name":"enable_app7",

Need to ignore NULL values when deserializing JSON

倖福魔咒の 提交于 2021-01-29 03:08:18
问题 I'm consuming some simple stock data in the form of JSON and plotting it on a chart. All works fine, except that some entries return NULL values because at that particular minute in time no trades were taken and therefore no price data is available. This creates gaps on the chart line. So if the "close" value is null, I want to exclude the entire block including the "minute" and "volume" from being added into the ObservableCollection, and just move on to include the next one whose values are

JsonConvert.Deserialize not recognizing array

一个人想着一个人 提交于 2021-01-28 23:00:35
问题 I'm a little stumped on this one. Everything I do to check this out says it is a valid Json array, but JsonConvert.Deserialize says it is an object. Can someone point out what I'm doing wrong? Code to replicate: var data = "[{\"User\": {\"Identifier\": \"24233\",\"DisplayName\": \"Commerce Test Student\",\"EmailAddress\": \"email@email.ca\",\"OrgDefinedId\": \"UniqueId1\",\"ProfileBadgeUrl\": null,\"ProfileIdentifier\": \"zzz123\"},\"Role\": {\"Id\": 153,\"Code\": null,\"Name\": \"Commerce

JsonConvert.Deserialize not recognizing array

左心房为你撑大大i 提交于 2021-01-28 23:00:06
问题 I'm a little stumped on this one. Everything I do to check this out says it is a valid Json array, but JsonConvert.Deserialize says it is an object. Can someone point out what I'm doing wrong? Code to replicate: var data = "[{\"User\": {\"Identifier\": \"24233\",\"DisplayName\": \"Commerce Test Student\",\"EmailAddress\": \"email@email.ca\",\"OrgDefinedId\": \"UniqueId1\",\"ProfileBadgeUrl\": null,\"ProfileIdentifier\": \"zzz123\"},\"Role\": {\"Id\": 153,\"Code\": null,\"Name\": \"Commerce

How can I reset a JsonReader instance instead of calling JToken.CreateReader?

依然范特西╮ 提交于 2021-01-28 21:52:44
问题 I have a large JSON file that I'm deserializing using Newtonsoft.Json - and I'm experiencing performance issues, esp. regarding one specific detail: While deserializing I need to use an IOC ("Inversion Of Control") Container to create the required instances. Inspired by https://skrift.io/issues/bulletproof-interface-deserialization-in-jsonnet/ and other sources I implemented a custom JsonConverter that overrides ReadJson . The method signature includes Type objectType , but e.g. in the case