Skip to content Skip to sidebar Skip to footer

Good .net Libraries For Working With Json Data?

I am currently trying out Json.NET, and it seems to work well. Any other good JSON libraries for .NET?

Solution 1:

There is the JavascriptSerialiser which is used by asp.net mvc and asp.net ajax. Also there is the DataContractJsonSerialiser used by WCF. The only problem I have encountered with the JavascriptSerialiser is that it uses funny way to serialise dates, which I do not think will parse into a javascript date. But this is easyly solved by this snippet

publicdoubleMilliTimeStamp()
    {
        DateTimed1=newDateTime(1970, 1, 1);
        DateTimed2= DateTime.UtcNow;
        TimeSpants=newTimeSpan(d2.Ticks - d1.Ticks);

        return ts.TotalMilliseconds;
    }

Solution 2:

The class JavaScriptSerializer from the System.Web.Script.Serialization namespace provides good JSON serialization/deserialization support.

Solution 3:

Jayrock works well and transparently turns your objects to and from JSON objects providing they have a public constructor. It also creates the script for you so you can just call your web service like a Javascript class.

Example:

publicclassPerson
{
  publicstring Name { get;set;}
  publicint Age { get;set; }

  publicPerson() { }
}

publicclassMyService : JsonRpcHandler
{
   [JsonRpcMethod("getBob")]
   public Person GetBob()
   {
       returnnew Person() { Name="Bob",Age=20};
   }
}

And the Javascript:

var service = new MyService();
var result = service.getBob();
alert(result.name); // JSON objects are camel-cased.

Post a Comment for "Good .net Libraries For Working With Json Data?"