• <legend id='rgGXd'><style id='rgGXd'><dir id='rgGXd'><q id='rgGXd'></q></dir></style></legend>
    <tfoot id='rgGXd'></tfoot>
    <i id='rgGXd'><tr id='rgGXd'><dt id='rgGXd'><q id='rgGXd'><span id='rgGXd'><b id='rgGXd'><form id='rgGXd'><ins id='rgGXd'></ins><ul id='rgGXd'></ul><sub id='rgGXd'></sub></form><legend id='rgGXd'></legend><bdo id='rgGXd'><pre id='rgGXd'><center id='rgGXd'></center></pre></bdo></b><th id='rgGXd'></th></span></q></dt></tr></i><div id='rgGXd'><tfoot id='rgGXd'></tfoot><dl id='rgGXd'><fieldset id='rgGXd'></fieldset></dl></div>
      <bdo id='rgGXd'></bdo><ul id='rgGXd'></ul>

      <small id='rgGXd'></small><noframes id='rgGXd'>

      1. 你能有一个包含破折号的属性名称吗

        时间:2023-08-24

          <tbody id='moSkU'></tbody>
      2. <small id='moSkU'></small><noframes id='moSkU'>

        <tfoot id='moSkU'></tfoot>
      3. <i id='moSkU'><tr id='moSkU'><dt id='moSkU'><q id='moSkU'><span id='moSkU'><b id='moSkU'><form id='moSkU'><ins id='moSkU'></ins><ul id='moSkU'></ul><sub id='moSkU'></sub></form><legend id='moSkU'></legend><bdo id='moSkU'><pre id='moSkU'><center id='moSkU'></center></pre></bdo></b><th id='moSkU'></th></span></q></dt></tr></i><div id='moSkU'><tfoot id='moSkU'></tfoot><dl id='moSkU'><fieldset id='moSkU'></fieldset></dl></div>

              <bdo id='moSkU'></bdo><ul id='moSkU'></ul>

              • <legend id='moSkU'><style id='moSkU'><dir id='moSkU'><q id='moSkU'></q></dir></style></legend>
                • 本文介绍了你能有一个包含破折号的属性名称吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  是否可以创建属性名称包含破折号的对象?

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

                  我正在创建一个匿名对象,以便可以使用 Json.Net 将其序列化为 Json,并且我需要的属性之一包含一个-"短划线字符.

                  I am creating an anonymous object so that I can serialize it to Json using Json.Net and one of the properties I need contains a '-' dash character.

                  我想要的一个例子是:

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

                  我知道我可以在创建对象时用下划线替换破折号,然后在序列化字符串中替换它们,但我想知道语言中是否有办法在没有这种解决方法的情况下做到这一点.

                  I know I could replace the dash with underscores when creating the object and then replace them in the serialized string afterwards, but wanted to know if there is a way in the language to do this without this workaround.

                  推荐答案

                  你不能用匿名对象做到这一点;字段名称必须是有效的标识符.您可以改为使用字典,Json.Net 应该像匿名对象一样轻松地对其进行序列化:

                  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<string, string>() {
                          { "acl", "public-read" },
                          { "bucket", "s3-bucketname" },
                          { "starts-with", "test/path" }
                      }
                  };
                  

                  这篇关于你能有一个包含破折号的属性名称吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:反序列化时的备用属性名称 下一篇:Json.NET 按深度和属性序列化

                  相关文章

                  最新文章

                  <legend id='XctfZ'><style id='XctfZ'><dir id='XctfZ'><q id='XctfZ'></q></dir></style></legend>
                      • <bdo id='XctfZ'></bdo><ul id='XctfZ'></ul>
                      <tfoot id='XctfZ'></tfoot>

                      <small id='XctfZ'></small><noframes id='XctfZ'>

                      <i id='XctfZ'><tr id='XctfZ'><dt id='XctfZ'><q id='XctfZ'><span id='XctfZ'><b id='XctfZ'><form id='XctfZ'><ins id='XctfZ'></ins><ul id='XctfZ'></ul><sub id='XctfZ'></sub></form><legend id='XctfZ'></legend><bdo id='XctfZ'><pre id='XctfZ'><center id='XctfZ'></center></pre></bdo></b><th id='XctfZ'></th></span></q></dt></tr></i><div id='XctfZ'><tfoot id='XctfZ'></tfoot><dl id='XctfZ'><fieldset id='XctfZ'></fieldset></dl></div>