回答

收藏

JSON 中可以使用注释吗?

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

我可以在 JSON 文件中使用注释吗?如果是这样,怎么办?
$ u, S& R$ c8 D* Z$ t& I% a                                                               
0 R2 I3 m: W1 S" a+ R- y    解决方案:                                                                ! Y  b6 C4 l. h$ t
                                                                JSON 只是数据,如果你包含注释,它也将是数据。: T  X5 A9 \2 U7 U4 n
您可以指定一个名字"_comment"(或其他)数据元素,应使用 JSON忽略了 数据的应用程序。
5 L, N* \* H2 h. l* s也许你最好生成/接收 JSON在 的过程中添加注释,因为他们应该提前知道 JSON 数据是什么,或者至少知道它的结构。1 ~% W% t: Y3 i1 s' o* S
但如果你决定:
) F' p! I' `( I# K6 F7 B: D[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]
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则