Elad Benda
Elad Benda

Reputation: 36654

How to serialize to json on C# application project (no Asp.net)?

I wrote an application project in c#. Is there a way to serialize a collection to Json string format? If I use C#4? C#3?

Another q: within Visual Studio 2010 ultimate I remember I could search and download dll from the web: Web Downlaoder or so. I cnnot find it again. Does any one know it?

TIA

Upvotes: 0

Views: 1165

Answers (5)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038820

JavaScriptSerializer is one way to go:

MyType[] collection = ...
string json = new JavaScriptSerializer().Serialize(collection);

Upvotes: 3

ryudice
ryudice

Reputation: 37366

Install Nuget http://nuget.org/ using visual studio extension manager, look for json.net in nuget (right click on your project and select Manage nuget packages), add it to your project, you can serialize using this library without adding dependency on system.web

Upvotes: 1

Adam Flanagan
Adam Flanagan

Reputation: 3052

Take a look at Json.net for the Json serialising/deserialising

For downloading the .dlls you probably saw nuget. Once it's installed you can right click on the references folder in the solution explorer and select manage packages.

Upvotes: 1

AD.Net
AD.Net

Reputation: 13399

Create a new JsonResult

Or take a look at Json Serialization

Upvotes: -1

Related Questions