Click here to Skip to main content
15,891,248 members
Everything / Deserialization

Deserialization

deserialization

Great Reads

by bk192077
I would like to define a C++ structure, pass the person instance to the mapping method along with JSON data, then use the filled structure. Or vice versa, get Person as JSON. StructMapping is trying to solve these problems.
by Dirk Bahle
Tips & Tricks on de/serializing Tree View based content with XML
by replaysMike
How to binary serialize your classes without having to modify them
by Robert P. Howard
How to deserialize a JSON string that contains nested polymorphic objects

Latest Articles

by bk192077
I would like to define a C++ structure, pass the person instance to the mapping method along with JSON data, then use the filled structure. Or vice versa, get Person as JSON. StructMapping is trying to solve these problems.
by Cinchoo
Use Cinchoo ETL to deserialize selective XML nodes from large XML file
by honey the codewitch
Designing infinitely scalable JSON: JSON (C++)
by Robert P. Howard
How to deserialize a JSON string that contains nested polymorphic objects

All Articles

Sort by Updated

Deserialization 

28 Aug 2023 by Randy Kroeger
What I have done in the past, where the serializer is returning null on Deserialize, is to test Serializing my object to see what the serializer is expecting. Once I see that result, I can fix my objects so they now Deserialize correctly.
15 Mar 2023 by vor_zakon_developer
I am new to XML. I want to read the following XML. Please help me on how to read the below XML in Java.
12 Jan 2023 by Codes DeCodes
I am consuming SOAP services from my application and I get following XMl content as response consuming .wsdl file in my code. Toyota Fortuner Japan ...
18 Oct 2022 by Virendra S from Bangalore, Karnataka
I have a json file which is having below data. { "ItemDiscount": { "enabled": true, "enableItemSelectionOnTenderScreen": true, "allowDiscountsForCanAdd": true, "allowDiscountsForExtra": true, "allowDiscountForVMUpcharge":...
18 Oct 2022 by Graeme_Grant
JSON Utils: Generate C#, VB.Net, SQL TAble and Java from JSON[^] is my go to for generating C# classes from Json. There are many other tools and helpful information below that will answer many questions for you... * Working with Newtonsoft.Json...
18 Oct 2022 by OriginalGriff
Start by using a converter to generate sample classes from the JSON: Convert JSON to C# Classes Online - Json2CSharp Toolkit[^] is the one I use. Then compare that to the classes you expect the deserialize to generate. If they aren't very, very...
21 Jul 2022 by Luis M. Rojas
I have the following code to connect to a Json on a server. I can connected and read the file succesfully. But i just want now to extract some fields, really i am stocked: I don't know even i have seen at lot examples (Including one in this...
21 Jul 2022 by Graeme_Grant
I have written an article that will answer this question and more: Working with JSON in C# & VB[^]
1 May 2022 by bk192077
I would like to define a C++ structure, pass the person instance to the mapping method along with JSON data, then use the filled structure. Or vice versa, get Person as JSON. StructMapping is trying to solve these problems.
9 Mar 2022 by Member 12654018
I am new on C# and also not hands on json. I want to deserialization this json data into C# objects but don't know how to deal with these guids "ae7da5d6-4024-4f7d-9221-5d2298afe650": {} in "menus" and "categories". Your help will be appreciate. ...
9 Mar 2022 by OriginalGriff
While C# supports GUID's JSON doesn't - they are represented by strings instead. However, that isn't technically valid JSON: the string to the left of a colon character is a field name, not a value, so your JSON example treats each new GUID...
9 Mar 2022 by RickZeeland
This CodeProject article might give you some clues: Working with JSON in C# & VB[^] It is also possible to use: Visual Studio - Edit - Paste Special - Paste JSON As Classes but that probably will not generate what you want :)
7 Nov 2021 by Cinchoo
Use Cinchoo ETL to deserialize selective XML nodes from large XML file
23 Jul 2021 by Member 8715089
I've found several posts similar to this request but nothing that I've been able to utilize to parse the response I get. If this is even possible, would someone be able to provide me sample vb.net code that would help with parsing/deserializing...
20 Jul 2021 by Member 11030334
I wrote an HTTPClient (.NET Core 3.x) that returns a JSON string but when I try to Deserialize it I run into issues. Issues ranging from can not deserialize array to string or the results are null. The string itself I can view on a Quick Watch...
20 Jul 2021 by Member 11030334
SOLVED I did not want to work with an OData Json object, so I had to strip the OData header and the rest just looked like a collection of JSON docs content = httpResponse.Content.ReadAsStringAsync().Result; var outer =...
23 Oct 2020 by Member 7874393
The json files are like the text below. { "lmod_file": { "crlmod": true, "name": "corn silage;Ffcult with disked radish cover, z4", "params": { "param": [ { "data": [ { ...
23 Oct 2020 by Sandeep Mewara
For the Json shared by you, following is the C# model class: public class Param { public object data { get; set; } public string name { get; set; } public string type { get; set; } public string value { get; set; } } public...
23 Oct 2020 by Chris Copeland
You've not explained what the error is exactly but you're trying to deserialize to a LmodFileClass but that class doesn't have the "lmod_file" property that's expected. Instead you've created the inner Rootobject class containing this, have you...
5 Oct 2020 by Robert P. Howard
How to deserialize a JSON string that contains nested polymorphic objects
5 Aug 2020 by Member 14779968
//Here is the Json { "groups": null, "data": [{ "type": 123, "name": "Name123" }, { "type": 567, "name": "SecondName" } ], "total": 2 } // I am then...
27 Mar 2020 by phil.o
You do not serialize the controls themselves, you just serialize the information needed to (re)build them.
27 Mar 2020 by patrickb123
I'm new into C# and would like to know how I can Serialize and Deserialize dynamically generated controls in a c# UserControl. If anyone could help me, i'll be very thankful. Thank you ! What I have tried: I have successfully done this in...
7 Oct 2019 by ksk
TestInfo node in the JSON does not match to the property TestInfoCollection. JsonConvert.DeserializeObject can leave reference type member properties null during deserialization without [JsonProperty] attribute on the property. Try this: 1. Synchronize the property name in the class and in the...
7 Oct 2019 by Paul Dietz
I’m attempting to deserialize the following Json string to c# .net class list collection, but the Jsonconvert.deserialize returns null. Can someone please explain to me what I’m doing wrong. string strjson = "{...
23 Jul 2019 by Danny96
Hello, I am (de)serializing the json strings to txt file. In my code object "c2" successfully does that where object "c1" fails to serialize and deserialize. Since object c1 fails, its boolean flags do not change. I searched for solutions, I saw some people merge the strings, and some use...
23 Jul 2019 by OriginalGriff
Look at what you are doing: string json = JsonConvert.SerializeObject(c1, Formatting.Indented); File.WriteAllText(path_combined, json); string json2 = JsonConvert.SerializeObject(c2, Formatting.Indented); File.WriteAllText(path_combined, json2); WriteAllText does what it says: creates a new...
17 Jul 2019 by OriginalGriff
JSON does not serialize fields - it only serialises properties, so MemberSerialization.OptIn will make no difference. Change your class: public class Class1 { public bool flag { get; set; } public bool flag2 { get; set; } public Class1() { ...
17 Jul 2019 by Danny96
I am trying to save the updated values(save and reload) to a text file When user closes, re-opens, we should see the where it left off. 1)In this code, I have a button that changes the flag values to true, BUT, the main class does not see the changed flag values. Still, the old values are...
16 May 2019 by Member 10536462
{ "Description": "This registry defines the events for the management processor.", "Id": "Events.json", "Messages": { "AEPSecureEraseFailed": { "Description": "Secure Erase of Intel Optane DC Persistent Memory has failed.", "Message": "Secure Erase of Intel Optane DC Persistent Memory...
16 May 2019 by Richard Deeming
Since all of the messages seem to share a common set of properties, try something like this: public class ErrorMessage { public string Description { get; set; } public string Message { get; set; } public string Resolution { get; set; } public string Severity { get; set; } ...
15 May 2019 by Graeme_Grant
As you're starting out with serialization of JSON data, this article answers this question and many others that you will have: Working with JSON in C# & VB[^]
15 May 2019 by RmcbainTheThird
Copy your json string to the clipboard and then from the edit menu in visual studio choose paste special.
15 May 2019 by phil.o
Json.NET[^] may also be useful.
15 May 2019 by TheRealSteveJudge
I would like to recommend json2csharp - generate c# classes from json[^] This site will generate a C# class from any valid JSON string. There is no need to write a corresponding C# class by hand.
12 Apr 2019 by #realJSOP
I wrote extension methods to return a default value if the element didn't exist. Go to this CP article: Downloads: SQLXAgent - Jobs for SQL Express - Part 1 of 6[^] and scroll down to SqlxCommon\FileExtensions, and look for ExtendLinqToXML.cs BTW, I generally don't us the built-in .Net...
12 Apr 2019 by Roger Tranchez
Hello, (* I'm using LinqPad to test this, that's why you can see the .Dump() call at the end of my sample) In this code, I'm getting "Instance validation error: '' is not a valid value for claves_sexo", because it is empty: void Main() { string xmlString =...
7 Mar 2019 by F-ES Sitecore
Your xml isn't valid. Replace with The XML represents a single Vehicles node not a list of them so change the code accordingly XmlSerializer xmlSerializer = new XmlSerializer(typeof(Vehicles)); System.IO.StreamReader sr =...
7 Mar 2019 by Gerry Schmitz
Your "FourWheeler" and "Outbound" tags are "not matched". i.e. your XML is invalid.
13 Feb 2019 by Paul Dietz
Why does jsoncovert deserialization return null? string strjson = "{\"testinfo\":" + "[{\"testid\":1,\"testshortdescription\":\"tanktest\",\"testlongdescription\":\"Tank Test \",\"testtypeid\":2,\"testlimitsid\":null}," + ...
13 Feb 2019 by OriginalGriff
Probably, your class names don't match. If I feed your JSON into a class generator (json2csharp - generate c# classes from json[^]) I get these: public class Testinfo { public int testid { get; set; } public string testshortdescription { get; set; } public...
12 Feb 2019 by Gerry Schmitz
The "case" doesn't match. The JSON element names are lower case; the class properties are upper case (the fields are lower case and not accessible).
9 Jan 2019 by ONeil Tomlinson
Hi have a scenario where i'm getting back json from an API that is using JsonAPI. the json returned can be of two formats as shown below. (simplified for this example) { "attributes":{ "AnimalType":"Lion", "Name":"lio", "Eats":"Meat" } } and ...
9 Jan 2019 by Graeme_Grant
I wrote an article to help with all different types of questions related to JSON deserialization. You can find the answer to your question in this article: Working with JSON in C# & VB[^]
18 Dec 2018 by SagarJaybhay1
The problem is because you add some class above the form1 class or whatever your form name. to resolve this error you need to add classes which you want to add below the form class.
18 Dec 2018 by sreeyush sudhakaran
When I added a class just above the form class my form designer not loading it showing error as given below as in call stackHide Call Stack at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)at...
3 Dec 2018 by replaysMike
How to binary serialize your classes without having to modify them
3 Dec 2018 by Member 14075735
globally, I have the following object: public class Geraet { public long Geraetenr { get; set; } public int Typ { get; set; } public string Platz { get; set; } public string Bezeichnung { get; set; } public int Tr { get; set; } public string...
22 Oct 2018 by Poonam Patel 10678835
From return Table From SP then JSONArray obj = new JSONArray(); try { for(int i = 0; i
22 Oct 2018 by Member 14029425
{ "emp": [ { "employeeId": 52374, "employeeName": "Mayuresh Chaudhary", "employeePhone": 7888119073, "project": "ZENLABS_IIOT", "manager": "Vikram Samdare", "status": "inactive", "assets": [ { "assetsNo": 30003, ...
22 Oct 2018 by Vikas Hire
hello,Bellow is My Web Service written in C#.In this, I got a return value and a table from database.I want to merge it into single JSON Object/Array. How can I do it..?con.Open(); SqlDataAdapter da = new SqlDataAdapter("UpdateUserInfo2 ", con); ...
5 Sep 2018 by Maciej Los
On the first look, Server class must be collection (array). I'd suggest to follow instruction from: .net - Generate C# class from XML[^] to create proper set of classes with their attirbutes. Please, read my tip too: A Complete Sample of Custom Class Collection Serialization and Deserialization[^]
5 Sep 2018 by User 13684037
I want to read the Servers in a Serverlist from the XML file and it shows me an error "error in xml document (2,2) and I dont know how to fix it and if the xml file systax has an error ? My Sourcecode: XmlSerializer serializer = new XmlSerializer(typeof(Server)); ...
24 May 2018 by Jinto Jacob
there are many reason for this exception. Please review the stack trace for more information about the error and where it originated in the code. there is a detailed description available ... click here to visit the link...
24 May 2018 by Shaikh Jani Ashraf
Hi I am getting the same exception when i convert the very large files data pulled from MongoDB and converted to string then to ASCII. Here is the line of code. Data = Encoding.ASCII.GetBytes(inputParameters.ToString()); where input parameters has DB data. And I have one more question is Is...
13 Apr 2018 by Alaa Ben Fatma
In this article, we will walk through the basic concepts of de/serialization and how to create a very basic de/serializer.
18 Jan 2018 by Graeme_Grant
This article goes into detail on how to Deserialize JSON and the tools that you can use to help you: Working with JSON in C# & VB[^] Here is the code generated by JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^]: namespace WhitePagesTool {         public class BelongsTo...
18 Jan 2018 by Dirk Bahle
Tips & Tricks on de/serializing Tree View based content with XML
14 Jan 2018 by Member 13621621
So I recently started coding again, and this forum has been MORE then helpful to me thus far. Anyways, I'm working on a simple form that snags a JSON String from a Web API and Deserializes it into a list box. However, any string that returns ANY null value errors out. I know this is a simple...
14 Jan 2018 by Graeme_Grant
The problem is that you're not mapping the JSON properties to the C# class properties correctly. This is why you are getting the error. Please look at Issues deserializing json in C# - Solution 1[^] to correctly map them.
14 Jan 2018 by Member 13621621
Form Code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Newtonsoft.Json; namespace WhitePagesTool { public partial...
13 Jan 2018 by Member 13621621
I appologize in advance as this is probably an easy fix, and going to be overly annoying for all who read it. However thanks in advance for ANY and ALL help given! I haven't coded in years, however recent events require me to pick back up again. I've never coded in anything except VB6, so this...
13 Jan 2018 by Thomas Daniels
Your code is:debugOutput("Name: " + jPerson.Name); But your property definition is: public string name { get; set; } So that's name rather than Name: C# identifiers are case-sensitive.
22 Dec 2017 by Dirk Bahle
Tips & Tricks on loading and saving WPF Tree View based content.
13 Nov 2017 by Claudio Trenca
#json # asp.net Hi everyone, I have a web service that gives me a json with this format: in case of positive login ["67", 1]; in the negative: ["fail", "Data entered for the user is incorrect."] how to properly deserialize? thank you all What I have tried: i try with : Dim ser As New...
13 Nov 2017 by Graeme_Grant
I ran your JSON sample through JSON Formatter & Validator[^] and it validates okay. Working with JSON in C# & VB[^] was written to answer questions like this one. Everything that you need to know is found in the article.
4 Oct 2017 by SheepSpeech
Hi guys, I'm trying to deserialize data from a xml file, and the xml follows an xsd file. I also generated a C# file containing classes from the xsd file. This code works fine: XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema;...
4 Oct 2017 by Atlapure Ambrish
Try to add the following annotations to the top of your class, remember xml is case sensitive [Serializable, XmlRoot("Dump")] public partial class Dump { }
18 Sep 2017 by Graeme_Grant
First, you have a problem with an invalid ending tag - here: blue should be: blue same with: white should be: white Next, You need to generate classes for your XML. Here are two options: Option 1. (Preferred) Here is a useful tool...
18 Sep 2017 by Member 13229879
I got deserializing working with single element. But when I have array of xml elements, my code is not working. Below is my code What I have tried: blue sedan ...
18 Sep 2017 by RickZeeland
I think you can do it like this, but you might have to change your class for this to work, I just used a "normal" class with public properties: string xml = File.ReadAllText(@"test.xml"); List res = new List(); var serializer = new XmlSerializer(res.GetType()); using...
8 May 2017 by Member 2127939
The code below currently works and loads XML into a class structure. This structure consists of a collection of items (items), each that have fixed properties and a collection that I use for a variable number of properties. Two things I want to do: 1) I want to change the list into something...
8 May 2017 by Richard Deeming
Assuming the elements in your XML file are actually cased correctly, and the missing closing elements are present, you just need to change the type of your KVPS property from: List> to List> You're currently using the built-in...
4 Apr 2017 by teledexterus
Error in jsone.count. using Newtonsoft; using Newtonsoft.Json; jsonr=[{"count":[{"first":1,"second":2,"third":3},{"first":11,"second":22,"third":33},{"first":111,"second":222,"third":333}]}] int oo = 0; int[,] jsona = new int[100, 9]; jCount jsone =...
4 Apr 2017 by Karthik_Mahalingam
public class jCount { public jPlace[] count { get; set; } } public class jPlace { public int first { get; set; } public int second { get; set; } public int third { get; set; } } public ActionResult...
22 Feb 2017 by Graeme_Grant
Here is a Converter Helper class (converted from C#) used in commercial applications. It will convert to/From POCOs JSON.Imports Newtonsoft.JsonPublic Class JsonConverter Public Shared Function FromClass(Of T)(data As T, Optional isEmptyToNull As Boolean = False, Optional...
22 Feb 2017 by Claudio Trenca
Hi, I'm fairly new to using JSON and I have a problem with deserialization of a json, I have a rest service that returns a JSON formatted like this: {result: [ { meta: [ [ "CODICE", "ftString", 16 ...
22 Feb 2017 by Richard Deeming
The problem you have is that the JSON you're trying to deserialize doesn't represent a List(Of JsonContract.Result). It actually represents a single object that looks something like this:' { result: [...] }Public Class ResultWrapper Public Property result As List(Of ResultSet)End...
26 Jan 2017 by Vikas Hire
Hello there's..I want to concatenate two json string.first string contains data tables records details and other string contains Count value.I get that values In data set such that.dataset ds.Tables[0]= //table records ds.tables[1]=// singale integer value (e.g....
26 Jan 2017 by Richard Deeming
Try something like this:json = JsonConvert.SerializeObject(new { contactList = ds.Tables[0], totalCount = ds.Tables[1].Rows.Cast().Select(r => r[0]).FirstOrDefault()}, Formatting.None);
9 Jan 2017 by Vikas Hire
hello,I want to get convert multiple data object into JSON string using C#.Like.. 1-I have a data table which I get from database using store procedureand 2-I have a string("userType:1") like this.I want to return both of data object (table and string) in my json String. How can I do it,...
9 Jan 2017 by virang_21
If you are using JSON.NET you can call Merge on two JSON Objects.JObject obj1 = JObject.Parse(@"{ 'field1': 'value1', 'field2': 'value2'}");JObject obj2 = JObject.Parse(@"{ 'field3': 'somevalue'}");obj1.Merge(obj2, new JsonMergeSettings { MergeArrayHandling =...
9 Jan 2017 by #realJSOP
3 Ways to Convert DataTable to JSON String in ASP.NET C#[^]
9 Dec 2016 by Luiey Ichigo
Hi,How to retrieve data from json file that have multiple line of data? Currently what I'm trying can be refer in "What I've tried"Below are the sample data:-[{ "DataType": "Spectre_DT", "HostName": "spectrum", "Listener": "c", "Timestamp":...
9 Dec 2016 by Luiey Ichigo
I have feel so bad where every time I post for question that I've been searching quite some times, I found the way for my own questions.To read the original format that been supplied by client:-{ "DataType": "Spectre_DT", "HostName": "spectrum", "Listener": "c", "Timestamp":...
7 Dec 2016 by Member 11266633
I have an xml. I want create class for this xml, but visual studio xml to class generator give not correct code. value ///...
16 Oct 2016 by Member 12794117
Hi,I am very new to web development and I am developing a web app using ASP.NET MVC 5.I have a requirement to deserialize a json string and store the values in C# ObjectsThis is how my JSON looks like{ "spellCheckQuery": "abc*", "searchStatus": "OK", "results": [ { ...
16 Oct 2016 by F-ES Sitecore
dobj.results should be a list of two result objects so you can use that as a datasource for your objects, or show them in a view like@foreach(var result in Model.results){ // your html here @result.id}
3 Aug 2016 by Member 5833550
if (str.Contains("QueueResponse_limit.json")) { QAfileName = str; // break; }Stream stream = assembly.GetManifestResourceStream(QAfileName); using (var reader = new StreamReader(stream,...
3 Aug 2016 by Bernhard Hiller
This means that the encoding is different from the encoding you expected. You may experiment with other encodings (i.e. replace Encoding.UTF8), or ask the people who wrote the service supplying the json data which encoding they use.
3 Aug 2016 by iProgramIt
Hello.I have yet another JSON deserialisation problem, and it's frustrating me. I have had a previous deserialisation problem (How do I deserialise "multi-level" JSON in VB.NET?[^]), and that was solved quickly. But I followed the steps to repeat that with yet another JSON string, and it's...
3 Aug 2016 by Bernhard Hiller
When comparing your class definitions and the Json text, my impression is that you received a Skins object - but: the textures property is NOT a List(Of Textures), but a single object of type Textures.
3 Aug 2016 by Member 12599808
why don't you deserialize your json dictonary of(string,object) and then the property of your class.Because i think so for multi level json it can not be easily deserialize because you have to make the exact structure of class for your json with exact names and their property.
2 Aug 2016 by iProgramIt
Hello all,I am trying to deserialise some JSON in Visual Basic.However, I am having a bit of trouble. I am using Newtonsoft.Json.But I seem to keep getting this error when I try to deserialise some JSON:The JSON...
2 Aug 2016 by F-ES Sitecore
In the JSON "properties" is an array (the square brackets indicate an array), even if there is only one item in the array. So your properties field needs to be a list of PropertyX. Don't know vb.net I'm afraid but I believe it's something like "as List Of PropertyX" rather than just "as PropertyX"
14 May 2016 by Rifath apps
i have created list and also created binary file called "login.bim" private void btnDelete_Click(object sender, EventArgs e) { List list = null; Log lg = new Log(); lg.Username = this.textBox1.Text; lg.Password =...
14 May 2016 by Rifath apps
The final Answer,, Itz working fine... please refer this code if any one has doubt or itz will use full some one private void btnDelete_Click(object sender, EventArgs e) { bool flag = false; int x = 0; Log lecObj = new Log(); ...
13 May 2016 by Patrice T
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.The debugger allow you to follow the execution line by line, inspect variables and you will see that there...