C# 如何将C对象序列化为json,使其看起来像;[“以”开头,“$key”和“user/john/”开头];?

C# 如何将C对象序列化为json,使其看起来像;[“以”开头,“$key”和“user/john/”开头];?,c#,json,json.net,C#,Json,Json.net,我正在尝试用C#创建一个viewmodel,它可以序列化为AmazonS3所需的json文档。文档。其中一个属性看起来像这样 ["starts-with", "$key", "user/john/"] C#对象是什么样子的,所以当它被序列化时会是这样的? 文档的其余部分如下所示 { "expiration": "2007-12-01T12:00:00.000Z", "conditions": [ {"acl": "public-read" }, {"buc

我正在尝试用C#创建一个viewmodel,它可以序列化为AmazonS3所需的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/"],

  ]

}

只需使用字符串数组

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/" }
    }
};
要填充它,您可以编写如下内容

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/" }
    }
};

只需使用字符串数组

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/" }
    }
};
要填充它,您可以编写如下内容

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/" }
    }
};