回答

收藏

JSON 中可以使用注释吗?

技术问答 技术问答 633 人阅读 | 0 人回复 | 2023-09-11

我可以在 JSON 文件中使用注释吗?如果是这样,怎么办?. O- U+ I$ S6 H# u) P# Y1 h
                                                                5 }* @- j" D& e
    解决方案:                                                               
% Q" ]! v# d; R- _6 ^                                                                JSON 只是数据,如果你包含注释,它也将是数据。9 ~" B- |" n8 h3 T1 v
您可以指定一个名字"_comment"(或其他)数据元素,应使用 JSON忽略了 数据的应用程序。
) b! w2 H6 Y5 t$ |也许你最好生成/接收 JSON在 的过程中添加注释,因为他们应该提前知道 JSON 数据是什么,或者至少知道它的结构。9 y) ]7 ~, L- J& }1 k
但如果你决定:  U0 u) n. _0 t! }# Z( \
[code]{   "_comment": "comment text goes here...",  "glossary": {       "title": "example glossary",     "GlossDiv": {          "title": "S",        "GlossList": {             "GlossEntry": {                "ID": "SGML",              "SortAs": "SGML",              "GlossTerm": "Standard Generalized Markup Language",                                                        "Acronym": "SGML",              "Abbrev": "ISO 8879:1986",              "GlossDef":                       "para": "A meta-markup language,used to create markup languages such as DocBook.",                 "GlossSeeAlso": ["GML","XML"]          "GlossSee": "markup"                       code]
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则