回答

收藏

JSON 中可以使用注释吗?

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

我可以在 JSON 文件中使用注释吗?如果是这样,怎么办?% `7 G9 f: ?! f. Z( u
                                                               
% ]- v& w# y* m- @2 ~( t    解决方案:                                                                9 h0 e* N" ^: c; N+ i, m/ p/ L
                                                                JSON 只是数据,如果你包含注释,它也将是数据。) y9 u! @5 A, O3 {( \
您可以指定一个名字"_comment"(或其他)数据元素,应使用 JSON忽略了 数据的应用程序。* L, n# u7 y5 C. x/ @) C9 G
也许你最好生成/接收 JSON在 的过程中添加注释,因为他们应该提前知道 JSON 数据是什么,或者至少知道它的结构。
( B& ]! o& Q8 g) l8 d但如果你决定:8 }& ^# L" s: `0 r$ _, k" M- N
[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]
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则