Click here to Skip to main content
15,891,253 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 Title

Deserialization 

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...
6 Apr 2016 by Sergey Alexandrovich Kryukov
Well, XmlSerializer is itself pretty bad and outdated, not fun to deal with (compared, say, to data contract based serialization). But with SOAP you have no choice but playing by SOAP rules, even though they are quite bad. And I don't see where you do it. In particular, I cannot see where you...
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.
22 Dec 2017 by Dirk Bahle
Tips & Tricks on loading and saving WPF Tree View based content.
18 Jan 2018 by Dirk Bahle
Tips & Tricks on de/serializing Tree View based content with XML
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...
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...
8 Aug 2013 by Antal Dominik
I'm trying to read a binary serialized object, that I don't have the object definition too. I took a peak into the file and saw property names, so I manually recreated the object (let's call it SomeDataFormat).I ended up with this : public class SomeDataFormat // 16 field { public...
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...
3 Dec 2018 by replaysMike
How to binary serialize your classes without having to modify them
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.
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...
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...
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...
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 RmcbainTheThird
Copy your json string to the clipboard and then from the edit menu in visual studio choose paste special.
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[^]
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; } ...
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...
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() { ...
7 Nov 2021 by Cinchoo
Use Cinchoo ETL to deserialize selective XML nodes from large XML file
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.
7 Dec 2015 by Gopi krishna.ch
Here I have a scenario that Create xml file dynamically and it should be serialisable and my xml is like...
7 Dec 2015 by Sergey Alexandrovich Kryukov
Instead of such lower-level serialization, you could use the most robust and easiest to use serialization method available in .NET FCL, Data Contract: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].See also my past answers:how to pass a datacontract from a C#/WCF code to Managed...
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[^]
13 Nov 2013 by Davide Ardizzola
Hi there,i've a problem with a strange xml and I don't know how to deserialize it.This is the xml:
21 Nov 2013 by Davide Ardizzola
I've solved making the classes with this tool: Simple XML to Code.Bye!Davide.
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...
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 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.
25 Feb 2014 by Qadeer Ahmed Khan
Hi, I want deserialize the data into list GoogleImageURLs but following code returns 0 records. Please help Thanks. [DataContract] public class GoogleImageURL : BindableBase { #region Feilds private int _width; private int _height; private...
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...
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.
18 Oct 2013 by cherry chelsea
This is my XML structure after serializing Task ID 1 Task Desc 1 ...
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[^]
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,...
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 =...
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...
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...
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:...
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}
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.
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 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[^]
25 Jun 2015 by Sudheer251
Does ServiceStack.Text has any Json Serializer/DeSerializer size limit ?
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);
12 Mar 2013 by Ariana Bond
Hi,I want to return a list containing DirectoryInfo , but i am getting an error of de-serialization.Please assist me how can i do this?Code Snippet--[OperationContract] private System.Collections.Generic.List GetSubDirectories(string directory) ...
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 =...
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...
12 May 2016 by Srikanth538
In your case, you needto use list.Remove(lg) not list.RemoveAll(lg).private void btnDelete_Click(object sender, EventArgs e) { List list = null; Log lg = new Log(); lg.Username = this.textBox1.Text; lg.Password =...
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) ...
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(); ...
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 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...
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.
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...
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 ///...
13 Mar 2015 by Member 11012009
Hello.I've got SOAP service which return datetime in format like "2015-01-22T11:23:15+0100".When I run WebMethod I get System.InvalidOperationException and message says that "2015-01-22T11:23:15+0100" is not valid AllXsd value.I want to change deserialization format of datetime, but I...
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"
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 =...
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...
27 Mar 2020 by phil.o
You do not serialize the controls themselves, you just serialize the information needed to (re)build them.
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); ...
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, ...
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 =...
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 #realJSOP
3 Ways to Convert DataTable to JSON String in ASP.NET C#[^]
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 =...
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")] ...
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 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 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...
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[^].
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...
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...
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...