Can you have a property name containing a dash

后端 未结 3 1577
自闭症患者
自闭症患者 2020-11-27 06:27

Is it possible to create an object with a property name that contains a dash character?

I am creating an anonymous object so that I can serialize it to Json using Js

3条回答
  •  一整个雨季
    2020-11-27 07:20

    You can't do this with anonymous objects; field names must be valid identifiers. You could instead use a Dictionary, which Json.Net should serialise just as easily as an anonymous object:

    var document = new {
        conditions = new Dictionary() {
            { "acl", "public-read" },
            { "bucket", "s3-bucketname" },
            { "starts-with", "test/path" }
        }
    };
    

提交回复
热议问题