views:

658

answers:

3

Hi

I am now using asp.net mvc and wondering what is a better choice using the built in Json or Json.Net I am not sure if one has an advantage over another.

Also if I do choose to go down the route of Json.Net then should I go with the stable version or beta 4? I am not sure how unstable the betas are.

+4  A: 

My thought is that I haven't found any problems with baked in Json. I would suggest going with that until you find something that doesn't work. Fewer dependencies makes simpler debugging.

Hurricanepkt
Totally agree. Json.net is a really nice library but unless you require features outside the .NET options its just an unnecessary dependency you need to manage.
jswanson
+5  A: 

You may have issues serializing dates with the MVC JSON. My answer to that post is repeated below.

If you are not tied to the MS JSON serializer you could use Json.NET. It comes with an IsoDateTimeConverter. This will serialize dates into an ISO 8601 formatted string.

For instance, in our project serializing myObject is handled via the following code.

JsonNetResult jsonNetResult = new JsonNetResult();
jsonNetResult.Formatting = Formatting.Indented;
jsonNetResult.SerializerSettings.Converters.Add(new IsoDateTimeConverter());
jsonNetResult.Data = myObject;

If you decide to take the Json.NET plunge you'll also want to grab JsonNetResult as it returns an ActionResult that can be used in ASP.NET MVC application. It's quite easy to use.

For more info see: Good (Date)Times with Json.NET

We are currently using Json.NET v3.5 Beta 4 and have not encountered issues. However, we haven't really taxed our system as it hasn't yet entered production. Your mileage may vary depending on how much of the framework you are using.

Hope this helps.

Ryan Taylor
A: 

In the past I have worked with a .NET JSON library that utilized an opt-in or opt-out method of denoting which members of a class are serialized. In reviewing the NerdDinner sample application I see a class in the SearchController called JsonDinner which looks like a regular Dinner class, but seems to be in existence only to properly output a few extra details that could be argued are only view related and not truly model related features. In this simple case, an attribute notation mechanism on the model, identifying the pieces to be serialized to JSON would result in a reduced amount of hand-maintained code.

Norman H