1

我正在尝试在 C# 中创建一个可以序列化为亚马逊 S3 所需的 json 文档的视图模型。文档在这里。其中一个属性看起来像这样,

 ["starts-with", "$key", "user/john/"] 

C# 对象会是什么样子,所以当它被序列化时它会像这样出来?文档的其余部分如下所示。

    { "expiration": "2007-12-01T12:00:00.000Z",

  "conditions": [

    {"acl": "public-read" },

    {"bucket": "johnsmith" },

    ["starts-with", "$key", "user/john/"],

  ]

}
4

1 回答 1

4

只需使用字符串数组

string[] data = new string[] { "starts-with", "$key", "user/john/" };

第二部分的对象结构类似于

public class S3Expiration {
    DateTime expiration { get; set; }
    object[] conditions { get; set; }
}

并填充它你会写类似

var expiration = new S3Expiration {
    expiration = DateTime.Now,
    conditions = new object[] {
        new { acl = "public-read" },
        new { bucket = "johnsmith" },
        new string[] { "starts-with", "$key", "user/john/" }
    }
};
于 2013-04-01T21:29:40.160 回答