packages.json中怎么添加注释?
如果文件很长,赶脚还是有添加注释的必要啊
可是添加了几个字,运行就报错鸟:( <img src="http://img.itc.cn/photo/ojDcyBJFEzN" /> <img src="http://img.itc.cn/photo/ojDc2ylMCgv" /> 肿么办?
37 回复
The JSON should all be data, and if you include a comment, then it will be data too.
不能加在"dependencies"里,但是可以加为package.json的最顶层项:
{
"//": "This is comment 1",
"//": "This is comment 2"
}
或者
{
"//": [ "Line 1 of Comments", "Line 2 of Comments" ]
}
和我说的其实一样:
The JSON should all be data, and if you include a comment, then it will be data too.
package.json就是一个json文件,json本身只是一种数据格式,而不是程序语言,一般程序语言都会支持注释,但作为数据格式,它本身并不支持注释,所以只能通过其他方式绕过了。
@kingapple 你这种需求是需要一个js 对象...而不是json...
var xx = {
xx : 'xx' //一波注释
}
//序列化这个js 对象...成json..
console.log(JSON.stringify(xx))
{
"//": "I am a comment",
"array": [
1,
2,
3
],
"//": "I am a comment too",
"object": {
"a": "b",
"c": "d",
"e": "f"
},
"string": "Hello World"
}