Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC json or Json.net?

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.

like image 832
chobo2 Avatar asked Aug 30 '09 02:08

chobo2


2 Answers

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.

like image 188
Ryan Taylor Avatar answered Sep 29 '22 22:09

Ryan Taylor


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.

like image 43
MarkKGreenway Avatar answered Sep 29 '22 21:09

MarkKGreenway