0

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

2
  • 1
    If you have two questions, please ask two questions. Commented Sep 30, 2011 at 15:40
  • I think the searching and downloading is handled by Nuget (nuget.org) Commented Sep 30, 2011 at 15:40

5 Answers 5

3

JavaScriptSerializer is one way to go:

MyType[] collection = ...
string json = new JavaScriptSerializer().Serialize(collection);
Sign up to request clarification or add additional context in comments.

2 Comments

I cannot reference Sytem.Web.Scripts from a non web-site poject.
@EladBenda, you need to reference the System.Web.Extensions assembly. If you are targeting the .NET 4.0 Client Profile you will need to switch to .NET 4.0 if you want to use this class. It can be done in desktop application but a reference to System.Web.Extensions is required.
1

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

Comments

1

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.

Comments

1

One way is to Use the DataContractJsonSerializer.

http://msdn.microsoft.com/en-us/library/bb410770.aspx

Comments

-1

Create a new JsonResult

Or take a look at Json Serialization

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.