Click here to Skip to main content
15,885,216 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 Score

Deserialization 

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.
18 Jan 2018 by Dirk Bahle
Tips & Tricks on de/serializing Tree View based content with XML
11 Oct 2015 by Maciej Los
2 notes:1) c# is case sensitive, which means that post is not equal to Post2) List(of comments) and List(of posts) is declared in wrong wayChange its declaration to:[Serializable, System.Xml.Serialization.XmlRoot("root"), System.Xml.Serialization.XmlType("root")]public class...
3 Dec 2018 by replaysMike
How to binary serialize your classes without having to modify them
5 Oct 2020 by Robert P. Howard
How to deserialize a JSON string that contains nested polymorphic objects
19 Jun 2014 by Maciej Los
If you want to know the way you can serialize and deserialize custom class collection, this tip is for you.
26 Jan 2016 by infal
How to write / read multidimensional arrays to/from BinaryWriter/BinaryReader or other stream using UnmanagedMemoryStream
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...
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.
15 May 2019 by phil.o
Json.NET[^] may also be useful.
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[^]
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() { ...
19 Oct 2012 by Sergey Alexandrovich Kryukov
I would say, this one:http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx[^].If helps you to serialize not just the object, but some arbitrary object graph. Also, it's totally non-intrusive. You only develop data types, with...
2 Nov 2012 by Alan N
I've just tried this and I can't see a problem with the deserialisation. Do you cast the individual items of CircuitData's elements list to their actual run-time type? CircuitData cd = Read(); // deserialise foreach (ElementData ed in cd.elements) { if (ed is...
30 Jan 2015 by Afzaal Ahmad Zeeshan
The problem is that the required assembly is not found in your project. In the first line of the Exception, it is stated clearly, that the assembly (you can say, the .dll library or the package) required to deserialize, is not found. Did you include that package inside your project? Include (or...
23 Feb 2015 by stibee
There you have the solution:https://msdn.microsoft.com/en-us/library/wkyt1t1f%28v=vs.110%29.aspx[^]
9 Aug 2015 by OriginalGriff
In VS 2013, you get an error message when you try this:The class frmInformation can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the...
6 Jan 2016 by Temirgali
Hi, everyone! I'm confused, i am new in programming and i need to professionals' help. I have mdf based database, and json data on web server. I must download all data from Web, and deserialize it and add to mdf datatable. Somebody help me.Json Data: [ ...
7 Jan 2016 by yeleswarapu ramakrishna
using System;using System.Collections.Generic;using System.Net;using System.Web.Script.Serialization;public partial class Practice : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { List objYourClass =...
13 May 2016 by Dmitriy Gakh
I have no enough data about your solution and logic, but this code seems working without runtime errors (if it does not resolve your problem completely, it could be helpful to improve the situation and understand the code better):private void btnDelete_Click(object sender, EventArgs e) ...
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"
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...
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...
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.
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.
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...
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...
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; } ...
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...
27 Mar 2020 by phil.o
You do not serialize the controls themselves, you just serialize the information needed to (re)build them.
21 Jul 2022 by Graeme_Grant
I have written an article that will answer this question and more: Working with JSON in C# & VB[^]
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 ...
6 Jul 2012 by Eugenij Maudza
Is there any existing solution to read object graph from binari serialized state without loading assemblies.On client side it would be greate to work with middleware classes without loading appropriate dll.The idea is to read metadata of object that was taken from server side. Probably...
19 Oct 2012 by ShacharK
Hey,I'm trying to write a protocol parser in C# which would be simple to maintain.My input is a Json payload, and I'm trying to convert it into a certain Request object in my inheritance-tree according to its identifier (which is obviously commonly named across all requests...).I'm...
1 Nov 2012 by Michael Szczepaniak
Hello. I have a problem with deserialization with my logic simulation program. Here are my element classes:public class AndGateData : TwoInputGateData { }public class TwoInputGateData : GateData { public TwoInputGateData() { Input2...
1 Nov 2012 by Mehdi Gholam
The XmlSerializer does not support polymorphism like you expect. Try using my fastJSON[^] project instead.
23 Nov 2012 by Prateek Kumar Pradeep Srivastava
Hi,Required: I want an xml file to be searialized like this John 1 David ...
23 Nov 2012 by Richard MacCutchan
Firstly this has nothing to do with Windows 8, it is purely a C# issue. Your class variables all have private visibility so cannot be seen outside of their classes. Add the public keyword to them and try again.
18 Feb 2013 by refisoft
try {String a="1000"; Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/fpt", "root", "root"); String select_blob = "select imag_save.img from imag_save inner join registration_stud on...
12 Jul 2013 by azeeth
Hi I have a need to deserialize an XML file which contains an image in base64 string. When I deserialize the XML the image is straight away populated as bytes by the following class. Which pretty much eliminates the need to do anything fancy and I write the image from those bytes. However a few...
8 Aug 2013 by E.F. Nijboer
Binary serialization is mostly suitable for use by an application internally and not really useful for data interchange. The obvious reason is that the format can be very specific between different framework versions. A better alternative would be to use xml or json formatters because these...
18 Oct 2013 by cherry chelsea
This is my XML structure after serializing Task ID 1 Task Desc 1 ...
19 Nov 2013 by Jocelyne El Khoury
I have the following json:{"Header": {"MCC": "415","FO": "0","REGID": "5" },"Contacts": [{ "NAME": "jocelyne", "MO": "70123456"},{ "NAME": "eliane", "MO": "03123456"}] }I have 2 clients: one client is giving me this json in this order, the second...
21 Nov 2013 by Davide Ardizzola
I've solved making the classes with this tool: Simple XML to Code.Bye!Davide.
7 Jan 2014 by gkishore84
I have a data contracts as follows: [DataContract] [KnownType(typeof(UserData))] [KnownType(typeof(CardData))] [XmlRoot(Namespace = Constants.XML_NMSP_TXN_MSG, ElementName = Constants.XML_TAG_COMMAND)] public class MessageData { [XmlAttribute("ID")] ...
13 Feb 2014 by tonyjoseph456
I'm developing my first client server android application. The client i.e, the android application gives request to find out the no of products submitted by the client in the server database. The server is sending the following data as string to the android application.//server sending the...
13 Feb 2014 by Maarten Kools
Android JSON Parsing Tutorial[^]JsonReader[^]Android JSON Parser Tutorial[^]JSON in Android - Tutorial[^]Android JSON Tutorial: Create and Parse JSON data[^]And much more to be found in Google[^]
25 Feb 2014 by Sergey Alexandrovich Kryukov
First, test you data model. Create some instance of data (with non-zero number of records). Using DataContractJsonSerializer, write this data in some file, then read it and write to another file, compare, review with your own eyes. And compare with the JSON file downloaded from the site.—SA
25 Feb 2014 by Jay Surendranath
1. Try a HttpClient instead of WebClient. It can read and return a string and you don't have go through the trouble of using a memorystream.2. The Json I received from this api is as follows: {"results":[...list of GoogleImageUrls..]} So create a type say ImageResults that has a...
21 Jul 2014 by Riccardo Macaluso
Hi guys! I have to ask you help for XML serialization.I have to deserialize this XML document (a piece of electronic invoice): IT 12345689 ...
21 Jul 2014 by Maciej Los
Here, on CP site, you'll find several articles about serialization and deserialization of XML. Please, use SearchBox[^] on the right-top corner of this site, for example: A Complete Sample of Custom Class Collection Serialization and Deserialization[^]
20 Aug 2014 by Member 11025073
Hi I have this Xml that I have to deserialize. YYYYMMDD HHMMSS 20100630 100000 ...
20 Aug 2014 by Sergey Alexandrovich Kryukov
Please see my comment to the question. If you have to work with the given file, serializers are poor helpers. Available serializers don't work with such a bare XML, they require a lot more metadata. So, more exactly, 1) you would need to create your own serializer matching this XML pattern,...
9 Sep 2014 by Saeed Jafarian
i have some list objects in my application and i want to serialize these lists and insert them to the database , then i want to Deserialize the binary data fetched from the database to remake the list againthanksthis is serialization part :::: MemoryStream departmanStream =...
9 Sep 2014 by Richard Deeming
By converting a varbinary column to a string, and then converting the string back to a series of bytes, you will end up corrupting the data.Try reading the bytes directly:byte[] serializedData = (byte[])dt_load.Rows[0][1];using (MemoryStream departmanStream = new...
18 Dec 2014 by Saeed Jafarian
Hii have an application in which i save my data, save it to the database and then fetch the data whenever i need it, something like save and restorei have list of objects (class) and serialize them to binary data then deserialize it for restoring,i can see that the data saved and restored...
18 Dec 2014 by Maciej Los
Please, read my comment to the question. That makes that direct answer is impossible.I'd suggest to read these:Serialization (C# and VB)[^]XML Serialization and Deserialization: Part-1[^]XML Serialization and Deserialization: Part-2[^]
17 Jan 2015 by Member 10627743
Hi When i ran the build of the code below it shows this error "Error 1 The non-generic type 'Newtonsoft.Json.JsonConvert' cannot be used with type arguments"Kindly help with an appropriate solutionClass:public class Devotion{ public string Date {get; set;} public...
17 Jan 2015 by Kornfeld Eliyahu Peter
Read the help carefully: http://james.newtonking.com/json/help/index.html?topic=html/T_Newtonsoft_Json_JsonConvert.htm[^]This line:d = JsonConvert.DeserializeObject(json);should be written like this:d = JsonConvert.DeserializeObject(json);
23 Jan 2015 by Member 10627743
HiWhen i ran the build i got this error "Cannot implicitly convert type 'DevotionJson.Devotion' to 'string'"//This is my classpublic class Devotion{ public string Date { get; set; } public string Title { get; set; } public string Verse { get; set; } ...
23 Jan 2015 by George Swan
Your getDevotion method is expecting you to return a string but you are trying to return a Devotion.
30 Jan 2015 by kavaan
i create a program which serialize a object and send to serverwhen i want deserialize this object :System.Runtime.Serialization.SerializationException: Unable to find assembly 'K1Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. at...
30 Jan 2015 by kavaan
but i dont use assembly or dll file...
23 Feb 2015 by Soft009
Hi,I have below SOAP response from the server and save it as string in my application. Now I need to deserialize the SOAP message.Sample responce"HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Content-Length: length
14 Mar 2015 by Member 10232616
I have been searching in many blogs and website to view the JSON data of erail.in apibut havent got any thing working. i am doing a project so i urgently need ityou can find api in: api.erail.in
14 Mar 2015 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
You can get answer at - How to deserialized JSON data into Datatable[^].Also another good article - How to Consume a JSON REST API in .NET[^].
28 Apr 2015 by Leo Chapiro
Basically take a look at this answer:Use XML reader instead of XML dom. XML dom stores the whole file in memory which is totally useless: XmlReader ClassYour second question:Quote:How to use/access "private ATXARPACKAGE[] aRPACKAGESField" Why have you made this variable...
28 Apr 2015 by Mehdi Gholam
Start here : http://stackoverflow.com/questions/15772031/how-to-parse-very-huge-xml-files-in-c[^]https://msdn.microsoft.com/en-us/library/bb387013.aspx[^]
12 May 2015 by James Gordon
hey guys! So I have been working on a project and it's 99% done,all I need to do is add in a Reader for XML.I have a Serialized Data Class that gets and sets most of my objects in my program. All variables are converted to data.FirstNames etc like so... private void...
12 May 2015 by Sergey Alexandrovich Kryukov
Stop suffering from the obsolete and ugly, use something much better, more powerful, consistent, flexible, universal and much easier to use: https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^].Please see my past answers:Creating property files...[^],How can I utilize...
27 May 2015 by dinesh_redhawk
Hello friends,We have a big XML file (>27MB) to be parsed. We had deserialized the XML file into a XmlData object. The data from the XML is perfectly saved in this XmlData object in a proper structure of classes and objects.Now, the goal here is to get the specific node data from the...
27 May 2015 by _Asif_
You can start by looking at below articleManipulate XML data with XPath and XmlDocument (C#)[^]
27 May 2015 by Acharya Raja Sekhar
Hi,I think you would like to deal with the deserialized object and want to find an object at specified path. Below code snippet might help you in doing this. class Program { static void Main(string[] args) { Student student = new Student { ID = 1,...
1 Jun 2015 by dinesh_redhawk
Hello friends,I have deserialized an XML and stored the data in an object (XmlData) public void CreateDeserializedXmlObject(string strSrcFilename) { try { //Using this object we can access the different classes & objects created...
6 Jul 2015 by Sergey Alexandrovich Kryukov
The question is not quite clear. Please see https://msdn.microsoft.com/en-us/library/system.windows.media.animation.storyboard%28v=vs.110%29.aspx[^].—SA
7 Jul 2015 by Jesse Cortis
Currently working on a program in vb.net that uses JSON.Net to read the destiny JSON files.This is the JSON file.{ "Response" : { "data" : { "membershipId" : "4611686018444289561", "membershipType" : 2, "characters" : [{ "characterBase" :...
7 Jul 2015 by Sergey Alexandrovich Kryukov
Please see my past answers:How To Convert object type to C# class object type[^],how to conver multi level json data to C# Object?[^],haw to get data from Cloudant (json document)[^].Ideally, the best situation is the one where you can use Data Contract, but it the JSON schema is...
8 Jul 2015 by Richard chiu
here is a solution using JavaScriptSerializer instead of Json.net. Both JavaScriptSerializer and json.net can be used interchangebly. here is the codePrivate Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim jss As New...
5 Aug 2015 by Bal000
Hi,i am having trouble deserializing Xml. I get AccountInformation to work but it wont work with the Leauges. The Xml doesnt contain any tag for "Leauges" and i dont want to add that tag to get it to work. Is there any other way to "fix" it? [Serializable()] ...
5 Aug 2015 by Kornfeld Eliyahu Peter
The problem is that your class declaration does not fit the XML format...What your code is expecting is a group of League nodes enclosed in a League node to form a kind of array: ... ... ...Now, you can change the structure of your XML to...
11 Aug 2015 by Saeed Jafarian
Helloi am working on a C# web application in which i have to save and restore the state of the application, i am doing this by serialization and deserialization. every thing works fine but the problem is when i deserialize list in which the object has a property from other class , then...
11 Aug 2015 by Sergey Alexandrovich Kryukov
Saeed Jafarian wrote:so if i use DataContractSerializer the problem should be solved, i don`t have problem with switching, i have tried 3 types of serializer up to now.i will try and make you know if this worksIf you do it, the problem will be sorted by using this:...
6 Apr 2016 by SURAJ-CDAC
Below is my stub classes generated by wsdl.exe[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)][System.Xml.Serialization.XmlArrayItemAttribute("entries", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]public partial...
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(); ...
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...
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 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 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.
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 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.
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": [ { ...
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 ///...
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":...
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); ...
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 #realJSOP
3 Ways to Convert DataTable to JSON String in ASP.NET C#[^]
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);