tags:

views:

54

answers:

0

I want to deserialize the following JSON string:

[
{"name":"photos","fql_result_set":[{"owner":"123456","caption":"Caption 1", "object_id":123},{"owner":"223456","caption":"Caption 2", "object_id":456}]},

{"name":"likes","fql_result_set":[{"object_id":123,"user_id":12156144},{"object_id":456,"user_id":140342725}]}
]

and get the POCO like

[DataContract]
public class Photo{

    [DataMember]
    public string owner{get;set;}

    [DataMember]
    public string caption{get;set;}

    [DataMember]
    public string object_id{get;set;}

}

[DataContract]
public class Like
{
    [DataMember]
    public string object_id { get; set; }

    [DataMember]
    public string user_id { get; set; }
}

What should I do?

I already have this piece of code:

public class JSONUtil
{
    public static T Deserialize<T>(string json)
    {
        T obj = Activator.CreateInstance<T>();
        MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
        System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
        obj = (T)serializer.ReadObject(ms);
        ms.Close();
        return obj;
    }