如何看待json语法中不能加注释的设计?

由于json中不能使用注释,使其不适合做配置文件,这算是Douglas老爷子的设计失误么?
关注者
43
被浏览
15717

6 个回答

是故意的:plus.google.com/+Dougla
I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn't.

Suppose you are using JSON to keep configuration files, which you would like to annotate. Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser.
如果你非要在 JSON 里面加上字段注释,可以用

"_comment": "comment text goes here...",

字段来表示,并没有特效,只是一个约定。javascript - Can I use comments inside a JSON file?