C Serialize List Of Objects

Posted : admin On 10/6/2019

To serialize a collection - a generic list, array, dictionary, or your own custom collection - simply call the serializer with the object you want to get JSON for. Json.NET will serialize the collection and all of the values it contains.

  1. C# Serialize List Of Strings
  2. C# Serialize Object To File
  3. C# Serialize And Deserialize Object
Active1 year, 5 months ago
  1. Jun 11, 2013  Hello everybody, I need to serialize a list of string text to xml and then desearialze it. List looks like 10, 6, 7, 11 and etc. How should I do this?
  2. Feb 06, 2016  How to serialize a list of objects using the XML Serializer in C#. How to Serialize Multiple and DIFFERENT Types of Objects in Java - Duration: 46:28. Lightfalls 8,715 views.
  3. How to implement custom JsonConverter in JSON.NET to deserialize a List of base class objects? 393 How can I change property names when serializing with Json.net?
  4. I need some suggestions on how to import data into multiple list objects using Dapper and then serialize the lists into proper JSON format. Please share your suggestions. Sample JSON fo.
Deserialize

I Use JsonConvert to serialize object and save it on database. It's sample of serialize string that I save in database:

Unable to download podcast iphone. [{'matId':'1','value':'44'},{'matId':'2','value':'55'},{'matId':'4','value':'77'}]

Now when I get this string from db it has a lot of backslash like this:

'[{'matId':'1','value':'44'},{'matId':'2','value':'55'},{'matId':'4','value':'77'}]'

And for this reason I can't Deserialize it.

.Replace(',') method doesn't any affect on this. Microsoft fonts list. I don't know why.

Mihai Alexandru-Ionut
32.1k6 gold badges50 silver badges82 bronze badges
user3748973user3748973

2 Answers

You have to use JsonConvert.Deserialize method.

C# Serialize List Of Strings

Your json string is wrapped within square brackets ([]), hence it is interpreted as array. Therefore, you need to deserialize it to type collection of one class, for example let's call it MyClass.

Here is Deserialize method.

Mihai Alexandru-IonutMihai Alexandru-Ionut
32.1k6 gold badges50 silver badges82 bronze badges

Backslashes represent serialized object. You need to deserialize your List object.You can try using Generics:

Natalia ZNatalia Z

C# Serialize Object To File

C Serialize List Of Objects

C# Serialize And Deserialize Object

Not the answer you're looking for? Browse other questions tagged c#asp.netjsonasp.net-mvcserialization or ask your own question.