gpt4 book ai didi

javascript - 为什么 JSON API 规范建议使用连字符/减号来分隔成员名称中的单词?

转载 作者:数据小太阳 更新时间:2023-10-29 05:29:13 26 4
gpt4 key购买 nike

根据 JSON API 上的推荐规范站点,我们应该使用 JSON 中的所有小写成员名称,并用连字符分隔:

The allowed and recommended characters for an URL safe naming of members are defined in the format spec. To also standardize member names, the following (more restrictive) rules are recommended:

Member names SHOULD start and end with the characters "a-z" (U+0061 to U+007A) Member names SHOULD contain only the characters "a-z" (U+0061 to U+007A), "0-9" (U+0030 to U+0039), and the hyphen minus (U+002D HYPHEN-MINUS, "-") as separator between multiple words.

所以基本上,我们应该像这样使用 JSON:

{
"first-name": "Jason",
"last-name": "Tough"
}

会不会成功cumbersome在 JavaScript 中访问这些属性?或者任何其他编程语言,特别是如果我们想从 JSON Schema 生成类?

此建议背后的动机是什么?

最佳答案

看起来问题引用中的 JSONAPI 命名不再有效。当前`JSONAPI recommends :

Naming

The specification places certain hard restrictions on how members (i.e., keys) in a JSON:API document may named. To further standardize member names, which is especially important when mixing profiles authored by different parties, the following rules are also recommended:

Member names SHOULD be camel-cased (i.e., wordWordWord)
Member names SHOULD start and end with a character “a-z” (U+0061 to U+007A)
Member names SHOULD contain only ASCII alphanumeric characters (i.e., “a-z”, “A-Z”, and “0-9”)

所以上面的例子应该是:

{
"firstName": "Jason",
"lastName": "Tough"
}

关于javascript - 为什么 JSON API 规范建议使用连字符/减号来分隔成员名称中的单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35191756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com