Activate your free membership today | Log-in

Tuesday, May 1st, 2007

Jayrock: JSON and JSON-RPC for .NET

Category: .NET, JSON, JavaScript

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:

C#:
  1.  
  2. <%@ WebHandler Class="JayrockWeb.HelloWorld" %>
  3.  
  4. namespace JayrockWeb
  5. {
  6.     using System;
  7.     using System.Web;
  8.     using Jayrock.Json;
  9.     using Jayrock.JsonRpc;
  10.     using Jayrock.JsonRpc.Web;
  11.  
  12.     public class HelloWorld : JsonRpcHandler
  13.     {
  14.         [ JsonRpcMethod("greetings") ]
  15.         public string Greetings()
  16.         {
  17.             return "Welcome to Jayrock!";
  18.         }
  19.     }
  20. }
  21.  

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:

JAVASCRIPT:
  1.  
  2.     var s = new HelloWorld();
  3.  
  4.     alert("sync:" + s.greetings());
  5.  
  6.     s.greetings(function(response) {
  7.       alert("async:" + response.result)
  8.     });
  9.  

Nice and simple.

Posted by Dion Almaer at 5:34 am
5 Comments

+++--
3.5 rating from 37 votes

5 Comments »

Comments feed TrackBack URI

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.

Comment by Morgan Roderick — May 1, 2007

Neat.

Comment by Rotev — May 7, 2007

Thanks.Good article

Comment by ermenisoykirmi — May 30, 2008

I have always enjoyed programming in JSON. Armenian Genocide

Comment by ArmenianGenocide — June 8, 2008

Case in point: Icegucci handbags Cube’s classic “Death Certificate,” which gucci women’s walletsmeshed the streets, sex gucci hysteria handbagsand politics in one prolific package. But today is different. If Cube gucci mens walletsdropped “Certificate” now, my guess is flower girl dressesit would be dead on arrival, unless he snared a couple of aion goldcameos from OJ da Juiceman.

Comment by wuwei — December 16, 2009

Leave a comment

You must be logged in to post a comment.