json.net

JSON deserialization with Stack structure reverses order [duplicate]

笑着哭i 提交于 2021-01-02 11:52:01
问题 This question already has answers here : JsonConvert.Deserializer indexing issues (4 answers) Closed 4 years ago . Using the NewtonSoft JSO serializer and a stack data structure. The order is reversed when I deserialize the structure. Comparing numbers and ss. Am I doing something wrong here or is there any workaround the issue. using Newtonsoft.Json; using System; using System.Collections.Generic; class Example { public static void Main() { Stack<string> numbers = new Stack<string>();

JSON deserialization with Stack structure reverses order [duplicate]

扶醉桌前 提交于 2021-01-02 11:40:09
问题 This question already has answers here : JsonConvert.Deserializer indexing issues (4 answers) Closed 4 years ago . Using the NewtonSoft JSO serializer and a stack data structure. The order is reversed when I deserialize the structure. Comparing numbers and ss. Am I doing something wrong here or is there any workaround the issue. using Newtonsoft.Json; using System; using System.Collections.Generic; class Example { public static void Main() { Stack<string> numbers = new Stack<string>();

How do I replace the OData V4 default Json Serializer with NewtonSoft's Json Serializer?

时光毁灭记忆、已成空白 提交于 2020-12-29 04:07:09
问题 I have a class that contains a List of DynamicObjects. I have a unit test that confirms that the Newtonsoft Json Serializer/Deserializer handles this correctly. However, the default OData Json Serializer/Deserializer does not. I implemented my own ODataEdmTypeDeserializer like this: public class JsonODataEdmTypeDeserializer : ODataEdmTypeDeserializer { public JsonODataEdmTypeDeserializer(ODataPayloadKind payloadKind) : base(payloadKind) { } public JsonODataEdmTypeDeserializer(ODataPayloadKind

How do I replace the OData V4 default Json Serializer with NewtonSoft's Json Serializer?

落花浮王杯 提交于 2020-12-29 04:06:31
问题 I have a class that contains a List of DynamicObjects. I have a unit test that confirms that the Newtonsoft Json Serializer/Deserializer handles this correctly. However, the default OData Json Serializer/Deserializer does not. I implemented my own ODataEdmTypeDeserializer like this: public class JsonODataEdmTypeDeserializer : ODataEdmTypeDeserializer { public JsonODataEdmTypeDeserializer(ODataPayloadKind payloadKind) : base(payloadKind) { } public JsonODataEdmTypeDeserializer(ODataPayloadKind

Converting JSON to Object fails - Cannot deserialize the current JSON object into System.Collections.Generic.List

时光怂恿深爱的人放手 提交于 2020-12-27 07:22:28
问题 I'm using the API of www.textlocal.in, which returns a JSON formatted object. JSON { "warnings":[ { "message":"Number is in DND", "numbers":"917000000000" } ], "balance":900, "batch_id":311110011, "cost":1, "num_messages":1, "message":{ "num_parts":1, "sender":"TXTLCL", "content":"Test1" }, "receipt_url":"", "custom":"", "inDND":[ "917000000000" ], "messages":[ { "id":"1350123781", "recipient":918819437284 } ], "status":"success" } My code with which I'm trying to parse the JSON: private void

Converting JSON to Object fails - Cannot deserialize the current JSON object into System.Collections.Generic.List

帅比萌擦擦* 提交于 2020-12-27 07:22:27
问题 I'm using the API of www.textlocal.in, which returns a JSON formatted object. JSON { "warnings":[ { "message":"Number is in DND", "numbers":"917000000000" } ], "balance":900, "batch_id":311110011, "cost":1, "num_messages":1, "message":{ "num_parts":1, "sender":"TXTLCL", "content":"Test1" }, "receipt_url":"", "custom":"", "inDND":[ "917000000000" ], "messages":[ { "id":"1350123781", "recipient":918819437284 } ], "status":"success" } My code with which I'm trying to parse the JSON: private void

JsonConvert.DeserializeObject<List<ConclusionEntityCategory>> is returning null objects in List

本秂侑毒 提交于 2020-12-27 03:08:55
问题 I am new to Json.Net and am having a difficult time deserializing my Json objects into .Net objects. It creates ConclusionEntityCategory objects but those in turn contain null objects. My code is as follows: const string catAndSubCat = @"[ { ""Category"": ""risk factor"", ""SubCategory2"": [ ""default"",""Minor risk factor"",""Major risk factor"" ] }, { ""Category"": ""intervention group"", ""SubCategory2"": [ ""default"",""Minor risk factor"",""Major risk factor"" ] } ]"; var c = JsonConvert

How to make Json Serialize ignore dictionary keys

五迷三道 提交于 2020-12-26 08:22:54
问题 I'm trying to serialize a dictionary within a class and the keys inside the CustomAttributes dictionary are getting formatted even though I've provided the ProcessDictionaryKeys parameter as false. I've added [JsonProperty] as shown below: [JsonProperty(NamingStrategyType = typeof(SnakeCaseNamingStrategy), NamingStrategyParameters = new object[] { false, false })] public IDictionary<string, string> CustomAttributes { get; set; } my CustomAttributes data looks like this: CustomAttributes = new

C# - deserialize JSON into ValueTuple

十年热恋 提交于 2020-12-26 04:57:15
问题 I'm trying to deserialize [{"foo": "1", "bar": false}, {"foo": "2", "bar": false}] into List<(string, bool)> type: JsonConvert.DeserializeObject<List<(string foo, bool bar)>>(json) But always get a list of default values - (null, false) . How can I achieve correct deserializing? P.S. I'm not interested in any model/class for that purpose. I need exactly value tuple instead. 回答1: The C# tuple feature was created to represent sets of values, not entities. The names of the values are like the

Create Json dynamically in c#

柔情痞子 提交于 2020-12-24 05:09:21
问题 I need to create a Json object dynamically by looping through columns. so declaring an empty json object then add elements to it dynamically. eg: List<String> columns = new List<String>{"FirstName","LastName"}; var jsonObj = new {}; for(Int32 i=0;i<columns.Count();i++) jsonObj[col[i]]="Json" + i; And the final json object should be like this: jsonObj={FirstName="Json0", LastName="Json1"}; 回答1: [TestFixture] public class DynamicJson { [Test] public void Test() { dynamic flexible = new