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,

1
  • Did you mean attributes or properties? And also what is the confusion, what did you try? Commented Jul 8, 2012 at 16:55

1 Answer 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.