Can you have a property name containing a dash

后端 未结 3 1589
自闭症患者
自闭症患者 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:01

    Not in c#, no. However most serializers allow you to customise this - often via attributes. IIRC with JSON.NET you want [JsonProperty("starts-with")] to specify the name. However you can't use attributes on anonymous types, so you may need to define a class with the properties (and attributes) the you desire.

提交回复
热议问题