首页 > 解决方案 > 是否可以在 Visual Basic 的一个 html.json 文件中添加多个片段?

问题描述

{
    "html":{
        "prefix": "html",
        "body": [
          "<!DOCTYPE html>",
          "<html lang='en'>",
          "<head>",
          "<meta charset='UTF-8'>",
          "<link rel='stylesheet' type='text/css' href=' '>",
          "<title>",

          "</title>",       
          "</head>",
          "<body>",

          "</body>",
          "</html>",
        ],
        "description": "html"
   }
}

{
  "css-doodle": {
      "prefix": "css-doodle",
      "body":[ 
          "<script src='https://unpkg.com/css-doodle@0.7.2/css-doodle.min.js'></script>", 
          "<css-doodle>",
          "content" ,
          "</css-doodle>",   
      ],
      "description": "doodle",
  }
}   

所以上面是html的两个片段。但是后一个 css-doodle 不起作用。代码中是否有一些错误或将两者分开的特定方式?

标签: htmlvisual-studiocode-snippets

解决方案


我看到它已经 8 个月了,所以把答案放在这里让其他人遇到。您的问题是您的描述后有一个文件括号结尾,并且您缺少逗号。您的第二个片段的开头还有一个文件括号的开头。

您的代码应如下所示:

{
    "html":{
        "prefix": "html",
        "body": [
          "<!DOCTYPE html>",
          "<html lang='en'>",
          "<head>",
          "<meta charset='UTF-8'>",
          "<link rel='stylesheet' type='text/css' href=' '>",
          "<title>",

          "</title>",       
          "</head>",
          "<body>",

          "</body>",
          "</html>",
    ],
    "description": "html"
   },



  "css-doodle": {
      "prefix": "css-doodle",
      "body":[ 
          "<script src='https://unpkg.com/css-doodle@0.7.2/css-doodle.min.js'></script>", 
          "<css-doodle>",
          "content" ,
          "</css-doodle>",   
      ],
      "description": "doodle",
  }
}   

基本上,对于您要添加的每个代码片段,只需在代码段后放置一个逗号,并将文件括号的结尾放置一次,在 json 的末尾。如您所见,后续片段的名称前没有括号。

希望这可以帮助。我知道我第一次想把头发扯掉。


推荐阅读