I'm having trouble porting this code below to c#. my main trouble is with the $fb_activity_array.
$fb_activity_message = '{*actor*} played this game';
$fb_activity_array = json_encode(array('message' => $fb_activity_message, 'action_link' => array('text' => 'Play Now','href' => 'http://yoururltoplaygamegere')));
Is this by any chance a Facebook app? It looks like you're trying to create a Stream post. If so, I recommend using the .NET Facebook API, which contains functions to do what you want, as well as some JSON formatting utilities if you need to do something manually.
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.