This isn't a perfect example, but this might put you on the right path. First create an object to hold your data.
public class activity
{
public activity(string message, object action_link)
{
Message = message;
Action_Link = action_link;
}
public string Message { get; set; }
public object Action_Link { get; set; }
}
public class action_link
{
public string Text { get; set; }
public string Href { get; set; }
public action_link(string text, string href)
{
Text = text;
Href = href;
}
}
Then you want to make a class like this to serialize it:
using System;
using System.Web;
using System.Web.Script.Serialzation;
public class activityHandler : IHttpHandler
{
public void ProcessRequest (HttpContext context) {
string message = "{*actor*} played this game";
string text = "Play Now";
string href = "http://yoururltoplaygamegere";
action_link link = new action_link(text, href);
activity act = new activity(message, link);
JavaScriptSerializer serializer = new JavaScriptSerializer();
context.Response.Write(serializer.Serialize(act));
context.Response.ContentType = "application/json";
}
public bool IsReusable
{
get
{
return false;
}
}
}
This will most likely give you the JSON structure you are looking for when serializing. You could turn the action_link object into a collection if that conforms to the standard you are looking to achieve so that you could have multiple action_link objects per activity object and so on and so forth. You can learn more about the serialization used in this example here:
JSON Serialization in ASP.NET with C#
Hope this helps.