My Visit to the MySpace OpenSocial Hack-A-Thon

 

Over the weekend I received an invitation to attend the MySpace OpenSocial Hack-a-thon where some top peeps would present where MySpace was with OpenSocial adoption.  A couple of IGN coworkers and I decided to check it out and took the drive to FIM HQ in Beverly Hills.  After some typical LA traffic, an accident on the freeway, loads of traffic on Santa Monica Blvd. and a couple wrong turns, we arrived 15 minutes late into a room of 50 people built for 20...  on with the hack-a-thon.

Hack-a-thon is misleading as there was no "hacking" or thon..ing  going on at all.  This turned out to be purely a presentation of how-tos and Q&A.  And although we were pleased to see how far along MySpace had come with implementation the lack of any hands on time was a bummer.  Nothing the free pizza didn't make up for though.

Expect to see a lot more from MySpace on the OpenSocial topic over the next month or two.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Capzles.com - Social Storytelling

A friend of mine, Chris Anderson, is taking the leap of faith and has started an Internet company called Capzles.com.  The idea is you tell a story using linear, time-based, layouts of media including photos, video, audio, blog entries, etc.  This could be your life, your vacations, a product history, biography, marketing promotion, whatever.  I love this idea.  In fact, I love it so much I had considered the same idea myself before I ever knew Chris was working on this project and we were literally 100 yards away from eachother in an office suite.  The initial force inside me was to capture a variety of details about my kids' lives which you can't capture in a photo album, photos site, blog, or any other form of album-like archiving I've seen.

Capzles explains their site with the following:

Capzles uniquely blends social networking and storytelling, allowing users to express themselves through combined videos, photos/images, blogs and music/audio along horizontal timelines (capzles) to share stories. From vacations to new product launches, Capzles lets anyone tell their stories in a fast, easy-to-use, high-style Flash interface that more accurately reflects personality and style. Capzles is where its audience is - everywhere on the Web - with its destination site, widget for personal Web space, or licensed software.

Today he presented his creation at Demo 08.  If you're not familiar with Demo and like new tech and startups, check it out.

If Capzles sounds interesting to you check out this video.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

.NET Framework 3.5 Info You Might Not Know

I may be the slow guy in the room...  .NET 3.5 installation includes Service Packs for .NET 2.0 SP1 and .NET 3.0 SP1, both of which replace previous versions.  I checked with our IT team and we've apparently not installed 2.0 SP1 "yet".  There's a concern of compatibility as previous upgrades from 1.0 caused some issues (before my time at this company).  I've not personally experienced problems with these in the past and I've worked with .NET since beta versions of 1.0.  If you'd like to do a quick check to see if .NET 2.0 SP1 is installed check out [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727\1033], "SP" should have a value of "00000001".  I checked a machine without .NET 2.0 SP1 and then checked a machine with .NET 3.5 and this holds true.

Check out these other entries from Heath Stewart for more info:

Microsoft .NET Framework 2.0 Service Pack 1, and How to Detect It (Includes 3.5 info.  Not really about detection, but the next link is.  Bad title for the content.)

Detecting Patches in .NET 2.0 and Visual Studio 2005

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

.NET Framework Source Now Available

As promised Microsoft has released some source for the .NET framework although not all libraries are available just yet.  From what I can tell you can currently only view the source through Visual Studio in debug mode.  Funny how MS's recommendation is to put the opening '{' on a new line yet the source I've seen so far has it on the same line as the method sig:).  You can view some details at the following locations:

Scott Guthrie's announcement

Shawn Burke's detailed instructions

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

A Generic JSON Serialization Extension Method Starring DataContractJsonSerializer

Download the sample code for this post. 

In October of 2007 The Gu wrote a ToJSON extension method using the JavaScriptSerializer class.  Since that time the JavaScriptSerializer class has been marked obsolete in favor of DataContractJsonSerializer.  In this post we’ll write an updated ToJSON method to satisfy every JSON extension method fantasy you have.  Quick agenda… the goal is to take a .Net object and convert it in to JSON text which would likely be consumed be a remote client.  Let’s start with the object to convert… an Address class.

using System.Runtime.Serialization;
 
...
 
[DataContract(Name = "Address", Namespace = "")]
public class PersonAddress
{
    [DataMember(Name = "City", Order = 1)]
    public string City { get; set; }
    [DataMember(Name = "Country", Order = 2)]
    public string Country { get; set; }
    [DataMember(Name = "PostalCode", Order = 3)]
    public string PostalCode { get; set; }
    [DataMember(Name = "State", Order = 4)]
    public string State { get; set; }
    [DataMember(Name = "Street", Order = 5)]
    public string Street { get; set; }
}


DataContract
and DataMember attributes provide information to the serialization process of how to structure the data.  It is possible to use the more familiar System.Serializable attribute however the output isn’t nearly as friendly.  More on that later.

The constructor for DataContractJsonSerializer we’re using requires knowledge of the Type of object being serialized to JSON.  For the purposes of this method we’re likely to not know which Type is to be serialized.  Quite often it will be a custom type.  We need our extension method to be more generic… I love .Net…  Here’s the method suitable for such a task:

using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;

...

public static string ToJSON<T>(this T obj)
{
    MemoryStream stream = new MemoryStream();
 
    try
    {
        //serialize data to a stream, then to a JSON string
        DataContractJsonSerializer jsSerializer = new DataContractJsonSerializer(typeof(T));
        jsSerializer.WriteObject(stream, obj);
 
        return Encoding.UTF8.GetString(stream.ToArray());
    }
    finally
    {
        stream.Close();
        stream.Dispose();
    }
}

 

Be sure to reference System.Runtime.Serialization and System.ServiceModel.Web.

Let’s dissect a bit.  DataContractJsonSerializer needs to know the object type.  In our case it’s generic, so we’ll let typeof(T) figure it out for us.  The serializer WriteObject method wants a stream to write the serialization output to for which we’re using a MemoryStream; an easy object for retrieving text from.  And that’s what we do… convert the stream’s byte array into a string; our JSON string.

Let’s run this pup using the following code:

PersonAddress address = new PersonAddress();
address.City = "Newport Beach";
address.Country = "US";
address.PostalCode = "92626";
address.State = "CA";
address.Street = "123 Candyland Way";
 
string json = address.ToJSON();
 
Response.Write(json);


And the results:

{"City":"Newport Beach","Country":"US","PostalCode":"92626","State":"CA","Street":"123 Candyland Way"}

Earlier I mentioned if you used the [Serializable] attribute instead of the [DataContract] attribute your solution would compile and function however your results would come out a bit different.  Here’s the output when using Serializable:

<{"<City>k__BackingField":"Newport Beach","<Country>k__BackingField":"US","<PostalCode>k__BackingField":"92626","<State>k__BackingField":"CA","<Street>k__BackingField":"123 Candyland Way"}>

As you can see this is far less friendly to work with from a JSON consumer perspective… Make it easier on yourself and stick with DataContract in this case.

I hope this helps in your JSON endeavors.  Let me know if you have any questions of problems!

Download the sample code for this post.

kick it on DotNetKicks.com
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

About Me

I'm Ian Suttle and I work for IGN Entertainment, a division of Fox Interactive Media.

Recent posts