Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialize to JSON in .NET 2.0

Tags:

json

c#

how can you serialize an object to JSON in .NET 2.0 using C#?

like image 281
PositiveGuy Avatar asked Jun 29 '09 00:06

PositiveGuy


People also ask

What is serialize to JSON?

Json namespace provides functionality for serializing to and deserializing from JavaScript Object Notation (JSON). Serialization is the process of converting the state of an object, that is, the values of its properties, into a form that can be stored or transmitted.

How do you serialize and deserialize an object in C# using JSON?

It returns JSON data in string format. In Deserialization, it does the opposite of Serialization which means it converts JSON string to custom . Net object. In the following code, it calls the static method DeserializeObject() of the JsonConvert class by passing JSON data.

Can you serialize a list in JSON?

Can JSON serialize a list? Json.NET has excellent support for serializing and deserializing collections of objects. 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.

What does JsonConvert DeserializeObject do?

Deserializes the JSON to the specified . NET type. Deserializes the JSON to the specified . NET type using a collection of JsonConverter.


2 Answers

You can use the JavaScriptSerializer class from ASP.NET Ajax 1.0, which is compatible with .NET 2.0.

like image 135
Joe Chung Avatar answered Sep 28 '22 04:09

Joe Chung


Did you try JSON.net ?

like image 33
J-16 SDiZ Avatar answered Sep 28 '22 04:09

J-16 SDiZ