Tuesday, May 1st, 2007
Jayrock: JSON and JSON-RPC for .NET
Jayrock is a modest and an open source implementation of JSON and JSON-RPC for the Microsoft .NET Framework, including ASP.NET. What's so modest about it? Well, modest as in plain and basic and no work of genius.
A developer creates a helloworld.ashx that contains your server side logic:
-
-
<%@ WebHandler Class="JayrockWeb.HelloWorld" %>
-
-
namespace JayrockWeb
-
{
-
using System;
-
using System.Web;
-
using Jayrock.Json;
-
using Jayrock.JsonRpc;
-
using Jayrock.JsonRpc.Web;
-
-
public class HelloWorld : JsonRpcHandler
-
{
-
[ JsonRpcMethod("greetings") ]
-
public string Greetings()
-
{
-
return "Welcome to Jayrock!";
-
}
-
}
-
}
-
Then you can access the file asking for a proxy via helloworld.ashx?proxy and you will see a test page. From code you can now:
-
-
var s = new HelloWorld();
-
-
alert("sync:" + s.greetings());
-
-
s.greetings(function(response) {
-
alert("async:" + response.result)
-
});
-
Nice and simple.












Another possible library for use with .NET would be http://www.newtonsoft.com/products/json/
I’ve succesfully used it in a commercial site, and it’s easy to work with and produces quality results, once you get your head around only serializing the stuff the client needs, instead of serializing EVERYTHING.
http://json.org has lot’s of good info.
Neat.
Thanks.Good article
I have always enjoyed programming in JSON. Armenian Genocide