1

I have created a generic extension method to serialize JSON using the DataContractJsonSerializer. looks like this:

public static string ToJSON<T>(this T obj) where T : class
{
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
    using (MemoryStream stream = new MemoryStream())
    {
       serializer.WriteObject(stream, obj);
       return Encoding.Default.GetString(stream.ToArray());
    }
}

I need to create a class, when serialize to json it should be like this :

{
     "expiration": "2011-04-20T11:54:21.032Z",
     "conditions": [
        ["eq", "acl", "private"],
        ["eq", "bucket": "myas3bucket"],
        ["eq", "$key", "myfilename.jpg"],
        ["content-length-range", 0, 20971520],
        ["eq", "$redirect", "myredirecturl"],
     ]
}

What are the attributes of this class?

Thanks,

4

1 回答 1

4

This should do the job:

DateTime expiration { get; set; }
string[][] conditions { get; set; }

You could also make conditions a List<List<string>>, or anything that's IEnumerable<IEnumerable<string>>, even List<string[]> should work.

于 2012-07-08T16:50:32.750 回答